当使用工厂进入角模块时,是否会出现跟随错误?
我有如下所示的工厂模块
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)发布于 2016-04-06 08:02:36
你没有从Poll给PollListCtrl工厂打电话
function PollListCtrl(Poll,$scope) {
$scope.polls = Poll.query();
}发布于 2016-04-06 08:05:14
您必须将pollServices注入控制器。
angular.module('polls', ['pollServices'])
.controller('PollListCtrl', PollListCtrl)
PollListCtrl.$inject = ["$scope", "pollServices"];
function PollListCtrl($scope, Poll) {
$scope.polls = Poll.query();
}https://stackoverflow.com/questions/36444901
复制相似问题