Reputation: 1078
I'm trying to figure out why Angular is giving me the following error on a provider I have not declared anywhere.
Error: $injector:unpr
Unknown provider: dblServiceProvider <-
Here's the skeleton of my factory:
angular.module('fv.services', [])
.factory('dblService', function($q, $http) {
this.getAll = function() {
var deferred = $q.defer();
var responsePromise = $http.post(URL, POSTPARAMS)
.success( function(data, status, header, config) {
// do something
})
return deferred.promise;
};
return {
getAll: getAll()
};
});
I try to instantiate that service in a controller, and this is where the error above is triggered.
.controller('searchCtrl', ['lotsOfInjections', 'dblService', function(lotsOfInjections, dblService) {
// do something
}]);
Why does Angular append "Provider" and look for a provider I haven't declared?
Upvotes: 2
Views: 500
Reputation: 691865
Because all services are created by a provider, and the provider of a service is always the service name followed by "Provider".
When you define a service foo
using a factory, Angular in fact creates a provider fooProvider
, that delegates to the factory to create the service instance. This provider is stored in the registry of service providers. When another component needs the service foo
, angular looks for fooProvider
in its registry.
Upvotes: 4