doo*_*ent 8 angularjs angularjs-resource
我有一个工厂,它返回我的文章模型的$资源:
angular.module('ADI.Resources').factory("Articles", ['$resource', function($resource) {
return $resource('/api/v1/article/:articleId', {
articleId: '@_id',
_shop: window.user._shop
}, {
update: {
method: 'PUT'
}
});
}]);
Run Code Online (Sandbox Code Playgroud)
GET,POST并且DELETE运行良好,但不是更新(PUT).这是我使用的代码:
Articles.update({articleId: '300000000000000000000001'}, function(article){
console.log(article);
});
Run Code Online (Sandbox Code Playgroud)
这是在提出这个要求:
PUT http://localhost:3000/api/v1/article?_shop=100000000000000000000001
Run Code Online (Sandbox Code Playgroud)
代替:
PUT http://localhost:3000/api/v1/article/300000000000000000000001?_shop=100000000000000000000001
Run Code Online (Sandbox Code Playgroud)
知道为什么在执行更新时没有填充:articleId参数?谢谢!
正如评论中提到的Fals一样,articleId参数位于请求内容中.所以我做了一个小技巧,让它也在URI上.
angular.module('ADI.Resources').factory("Articles", ['$resource', function($resource) {
return $resource('/api/v1/article/:articleId', {
articleId: '@_id',
_shop: window.user._shop
}, {
update: {
method: 'PUT',
params: {
articleId: "@articleId"
}
}
});
}]);
Run Code Online (Sandbox Code Playgroud)