Angularjs ngResource:对象没有方法查询
试图使ngResource工作,但出现错误:Angularjs ngResource:对象没有方法查询,angularjs,ngresource,Angularjs,Ngresource,试图使ngResource工作,但出现错误: var srcControllers = angular.module('srcControllers', ['ngResource']); srcControllers.controller('RotationListCtrl', ['$scope', '$location', 'Rotation', function($scope, Rotation, $location) { Rotation.query(function(data)
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);
};
}]);
对象#没有方法“query”
我试着让它尽可能简单,根据我能找到的文档/帖子,这应该行得通。但事实并非如此
这是我的服务/工厂:
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);
};
}]);
试试这个
var srcControllers = angular.module('srcControllers', ['ngResource', 'srcServices']);
您正在将服务创建为新的角度模块。因此,为了访问服务,您必须将其注入控制器。对于小型化,依赖项注入的顺序必须相同<代码>srcControllers.controller('RotationListCtrl',['$scope','$location','Rotation',function($scope,$location,Rotation){}。注意,
$location
是第二个参数,Rotation
是第三个参数。即使我没有使用缩小的js,这仍然有效。谢谢!这似乎没有任何区别。相同的错误。