Angular JS Unknown Provider Error
I am getting this error in my angular js application and cannot figure out what is causing the problem. This seems to be a common problem, but all of my problems didn't help. If anyone can point out what the problem might be, that would be appreciated. Thank:)
Error: [$ injector: unpr] Unknown provider: ResultsServiceProvider <- ResultsService <- ResultsController
Here is my code:
app.js
angular.module('resultsApp', ['ngRoute', 'nvd3', 'ngResource'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/results', {
controller: 'ResultsController',
templateUrl: 'app/results/Results.html'
});
}])
controller
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;
);
};
}
Services:
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);
}
}
Factory
angular
.module('resultsApp')
.factory('ResultFactory', ResultFactory);
function ResultFactory($resource) {
return $resource('api/results', {}, {
get: {method: 'get', isArray: true}
});
}
+3
source to share
1 answer
If you have an error like this:
Error: [$ injector: unpr] Unknown provider: ResultsServiceProvider <- ResultsService <- ResultsController
This usually means one of the following things:
- When you create (declare) you either run the name
ResultsService
. - Or you have n't added a script tag pointing to the file containing the service in your
index.html
. - Or you created a service in a specific module other than the main application module, but forgot to list that module as one of your application dependencies (for example
angular.module('myApp', ['moduleWithService']);
)
Therefore, when debugging these kinds of errors, you should always start by checking these three things.
+5
source to share