我正在处理用户对象。我的服务文件:
angular.module('UserService',['ngResource']).factory('User', function($resource){
var User = $resource('/api/users/:id',
{
list: { method: 'GET' },
lock: { method: 'PATCH' }
}
);
return User;
});
用户列表运行良好
<div ng:controller="UserController">
<ul>
<li ng-repeat="user in users">
<a ng:click="select(user)">
{{user.first_name}} {{user.last_name}}
</a>
</li>
</ul>
</div>
和项目文件:
var app = angular.module('module-users', ['UserService']);
app.config(function($routeProvider, $interpolateProvider) {
$routeProvider.when('/', {
controller: UserController,
templateUrl: Routing.generate('template_user_list')
});
});
function UserController($scope, User){
$scope.users = User.query();
$scope.selectedUser = null;
$scope.select = function(user){
$scope.selectedUser = user;
}
$scope.lock = function(user){
user.lock();
console.log('lock user');
}
}
但是,当我想执行用户锁定/解锁时,我收到一条错误消息,指出方法未知。有什么想法有什么问题吗?如何通过服务执行锁定?还有其他建议吗?
TypeError: Object #<Resource> has no method 'lock'