我正在尝试为$资源定义自定义getUsers操作,但是我得到一个错误,该对象没有getUsers方法。
angular.module('myApp')
.factory('Customer', ['$resource', 'apiUrl', function ($resource, apiUrl) {
return $resource(apiUrl + '/customers/:id', {
query: {method: 'GET', isArray: true},
get: {method: 'GET'},
getUsers: {method: 'GET', url: apiUrl + '/customers/:id/users', isArray: true}
});
}]);
将其与Customer.getUsers({id: 'id'})
我正在使用1.2.0-rc2。我在这里缺少什么?
答案 0 :(得分:1)
angular.module('myApp')
.factory('Customer', ['$resource', 'apiUrl', function ($resource, apiUrl) {
return $resource(apiUrl + '/customers/:id', {
query: {method: 'GET', isArray: true},
get: {method: 'GET'},
getUsers: {method: 'GET', url: apiUrl + '/customers/:id/users', isArray: true}
});
}]);
替换为:
angular.module('myApp')
.factory('Customer', ['$resource', 'apiUrl', function ($resource, apiUrl) {
return $resource(apiUrl + '/customers/:id', { id: 'id' }, { //here add { }
query: {method: 'GET', isArray: true},
get: {method: 'GET'},
getUsers: {method: 'GET', url: apiUrl + '/customers/:id/users', isArray: true}
});
}]);