为什么必须在 $resource angularjs 中设置 update: { method: 'PUT' }?
why must set update: { method: 'PUT' } in $resource angularjs?
我在meanjs中有示例代码,我不明白为什么他们必须设置第三个参数
update: {
method: 'PUT'
}
这是完整代码:
'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'
}
});
}
]);
提前致谢。
如果您查看 Returns 部分下的 docs,您会发现 $resource
服务将 return:
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'} };
它进一步指出:
The actions save, remove and delete are available on it as methods with the $ prefix.
因此 $save
、$remove
、$delete
可用但没有 $update。这就是示例中的服务具有以下行的原因:
...
'update': { method: 'PUT'},
...
它旨在扩展这些默认操作集,以便 $update
可以作为对象的方法使用,并且它将使用 HTTP PUT 方法而不是像其他方法一样的 GET/POST/DELETE。
注意:以上答案摘自,但我已将您应该关注的部分隔离在此处
我在meanjs中有示例代码,我不明白为什么他们必须设置第三个参数
update: {
method: 'PUT'
}
这是完整代码:
'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'
}
});
}
]);
提前致谢。
如果您查看 Returns 部分下的 docs,您会发现 $resource
服务将 return:
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'} };
它进一步指出:
The actions save, remove and delete are available on it as methods with the $ prefix.
因此 $save
、$remove
、$delete
可用但没有 $update。这就是示例中的服务具有以下行的原因:
...
'update': { method: 'PUT'},
...
它旨在扩展这些默认操作集,以便 $update
可以作为对象的方法使用,并且它将使用 HTTP PUT 方法而不是像其他方法一样的 GET/POST/DELETE。
注意:以上答案摘自