[英]why must set update: { method: 'PUT' } in $resource angularjs?
I have sample code in meanjs, i don't understand why they must set third paprameter 我在meanjs中有示例代码,我不明白为什么他们必须设置第三个参数
update: {
method: 'PUT'
}
This is full code: 这是完整的代码:
'use strict'; //Articles service used for communicating with the articles REST endpoints angular.module('articles').factory('Articles', ['$resource', function ($resource) { return $resource('api/articles/:articleId', { articleId: '@_id' }, { update: { method: 'PUT' } }); } ]);
Thanks in advance. 提前致谢。
If you take a look at the docs specifically under the Returns section you'll see that the $resource
service will return: 如果您仔细查看Returns部分下的文档,您会发现$resource
服务将返回:
A resource "class" object with methods for the default set of resource actions optionally extended with custom actions. 资源“类”对象,具有用于资源操作的默认集合的方法,可以选择使用自定义操作进行扩展。 The default set contains these actions: 默认设置包含以下操作:
{'get': {method:'GET'},
'save': {method:'POST'},
'query': {method:'GET', isArray:true},
'remove': {method:'DELETE'},
'delete': {method:'DELETE'} };
It further states: 它进一步指出:
The actions save, remove and delete are available on it as methods with the $ prefix. 保存,删除和删除操作可以作为带有$前缀的方法使用。
So $save
, $remove
, $delete
are avaiable but no $update. 因此$save
, $remove
, $delete
可用,但没有$ update。 This is why the service in the example has the line: 这就是示例中的服务包含以下行的原因:
...
'update': { method: 'PUT'},
...
It's meant to extend these default set of actions so that $update
will be available as a method on the objects and it will use the HTTP PUT method instead of GET/POST/DELETE like the others. 这是为了扩展这些默认的操作集,以便$update
可以作为对象上的方法使用,并且它将使用HTTP PUT方法而不是像其他方法一样使用GET / POST / DELETE。
Note: the above answer was extracted from a previous question I answered but I've isolated the part you should focus on here 注意:以上答案摘自我回答的上一个问题,但我隔离了您应该在此处关注的部分
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.