【发布时间】:2015-09-14 16:11:07
【问题描述】:
我在我的 Angular js 应用程序中遇到此错误,无法找出导致问题的原因。这似乎是一个常见问题,但我所有的故障排除都没有帮助。如果有人能指出问题所在,我们将不胜感激。谢谢:)
错误:[$injector:unpr] 未知提供者:ResultsServiceProvider
这是我的代码:
app.js
angular.module('resultsApp', ['ngRoute', 'nvd3', 'ngResource'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/results', {
controller: 'ResultsController',
templateUrl: 'app/results/Results.html'
});
}])
控制器
angular
.module('resultsApp')
.controller('ResultsController', ResultsController);
function ResultsController($scope, ResultsService) {
$scope.teams = [{teamA: ''}, {teamB: ''}];
$scope.premResults = [];
$scope.searchByTeams = function () {
ResultsService.getResultsList($scope.teams.teamA,$scope.teams.teamB, function (res) {
$scope.premResults = res;
);
};
}
服务:
angular
.module('resultsApp')
.service('ResultsService', ResultsService);
function ResultsService(ResultFactory) {
this.getResultsList = getResultsList;
function getResultsList(teamA, teamB, callback) {
return ResultFactory.get({teamA: teamA, teamB: teamB}, callback);
}
}
工厂
angular
.module('resultsApp')
.factory('ResultFactory', ResultFactory);
function ResultFactory($resource) {
return $resource('api/results', {}, {
get: {method: 'get', isArray: true}
});
}
【问题讨论】:
-
你的
ResultsService的js 文件是否链接在index.html中? -
谢谢——我真笨!这让它工作了!
-
:) 很高兴有一个检查清单来查看这些错误的位置。我会在一秒钟内编译一个答案。
标签: angularjs angularjs-service angularjs-factory