kel*_*nia 3 angularjs angularjs-service angularjs-factory
我在我的角度js应用程序中收到此错误,无法弄清楚导致问题的原因.这似乎是一个常见的问题,但我的所有故障排除都没有帮助.如果任何人都可以指出问题可能会受到赞赏.谢谢 :)
错误:[$ injector:unpr]未知提供者:ResultsServiceProvider < - ResultsService < - ResultsController
这是我的代码:
app.js
angular.module('resultsApp', ['ngRoute', 'nvd3', 'ngResource'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/results', {
controller: 'ResultsController',
templateUrl: 'app/results/Results.html'
});
}])
Run Code Online (Sandbox Code Playgroud)
调节器
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;
);
};
}
Run Code Online (Sandbox Code Playgroud)
服务:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
厂
angular
.module('resultsApp')
.factory('ResultFactory', ResultFactory);
function ResultFactory($resource) {
return $resource('api/results', {}, {
get: {method: 'get', isArray: true}
});
}
Run Code Online (Sandbox Code Playgroud)
如果您有这样的错误:
错误:[$ injector:unpr]未知提供者:ResultsServiceProvider < - ResultsService < - ResultsController
它通常意味着其中一件事:
ResultsService名字.index.html.angular.module('myApp', ['moduleWithService']);)因此,在调试此类错误时,您应该始终从检查这三件事开始.
| 归档时间: |
|
| 查看次数: |
5795 次 |
| 最近记录: |