【发布时间】:2014-05-16 06:48:54
【问题描述】:
试图让 ngResource 工作,但出现错误:
对象#没有方法'查询'
我已尝试使其尽可能简单,并且根据我能找到的文档/帖子,这应该可行。但事实并非如此。
这是我的服务/工厂:
var srcServices = angular.module('srcServices', ['ngResource']);
srcServices.factory('Rotation', ['$resource',
function ($resource) {
return $resource('/rotations/:id' );
}]);
这是触发错误的控制器代码:
var srcControllers = angular.module('srcControllers', ['ngResource']);
srcControllers.controller('RotationListCtrl', ['$scope', '$location', 'Rotation', function($scope, Rotation, $location) {
Rotation.query(function(data) {$scope.rotations = data;})
$scope.edit = function(a) {
var path = "/rotations/" + a._id.$oid;
$location.path(path);
};
}]);
【问题讨论】:
-
为了缩小,依赖注入必须以相同的顺序。
srcControllers.controller('RotationListCtrl', ['$scope', '$location', 'Rotation', function($scope, $location, Rotation) { }。注意$location是第二个参数,Rotation是第三个。 -
即使我没有使用缩小的 js,这也有效。谢谢!
标签: angularjs ngresource