angular.min.js:63 引用错误
angular.min.js:63 ReferenceError
在 angular 模块中使用工厂时出现以下错误
我有如下的工厂模块
angular.module('pollServices', ['ngResource']).factory('Poll', function($resource) {
return $resource('polls/:pollId', {}, {
query: { method: 'GET', params: { pollId: 'polls' }, isArray: true }
})
});
我在同一个文件中有另一个名为 polls
的模块,我需要在这个应用程序中使用工厂模块,所以我在模块配置中调用了它,例如
angular.module('polls', ['pollServices'])
当我像这样调用这个模块中的工厂时
function PollListCtrl($scope) {
$scope.polls = Poll.query();
}
我收到类似
的错误
angular.min.js:63 ReferenceError: Poll is not defined
at new PollListCtrl (app.js:29)
您没有从 PollListCtrl
调用 Poll
工厂
function PollListCtrl(Poll,$scope) {
$scope.polls = Poll.query();
}
您必须将 pollServices 注入控制器。
angular.module('polls', ['pollServices'])
.controller('PollListCtrl', PollListCtrl)
PollListCtrl.$inject = ["$scope", "pollServices"];
function PollListCtrl($scope, Poll) {
$scope.polls = Poll.query();
}
在 angular 模块中使用工厂时出现以下错误
我有如下的工厂模块
angular.module('pollServices', ['ngResource']).factory('Poll', function($resource) {
return $resource('polls/:pollId', {}, {
query: { method: 'GET', params: { pollId: 'polls' }, isArray: true }
})
});
我在同一个文件中有另一个名为 polls
的模块,我需要在这个应用程序中使用工厂模块,所以我在模块配置中调用了它,例如
angular.module('polls', ['pollServices'])
当我像这样调用这个模块中的工厂时
function PollListCtrl($scope) {
$scope.polls = Poll.query();
}
我收到类似
的错误angular.min.js:63 ReferenceError: Poll is not defined
at new PollListCtrl (app.js:29)
您没有从 PollListCtrl
Poll
工厂
function PollListCtrl(Poll,$scope) {
$scope.polls = Poll.query();
}
您必须将 pollServices 注入控制器。
angular.module('polls', ['pollServices'])
.controller('PollListCtrl', PollListCtrl)
PollListCtrl.$inject = ["$scope", "pollServices"];
function PollListCtrl($scope, Poll) {
$scope.polls = Poll.query();
}