我正在关注Angular主页,我扩展了$ resource以添加更新方法,如下所示:
angular.module('user', ['ngResource']).
factory('User', function($resource) {
var User= $resource('/user/:id', {
update: {
method: 'PUT'
}
});
User.prototype.update = function(cb) {
return User.update({ // this line throws the error
id: this.id
}, angular.extend({}, this, {
_id: undefined
}), cb);
};
Run Code Online (Sandbox Code Playgroud)
但运行:
$scope.user.update()
Run Code Online (Sandbox Code Playgroud)
抛出TypeError:对象函数h(a){v(a || {},this)}没有方法'update'
我现在无法看到我所缺少的任何帮助
我发现问题其实我需要为paramDefaults arg传递一个空对象:
var User= $resource('/user/:id', {}, {
update: {
method: 'PUT'
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11614 次 |
| 最近记录: |