Wottensprels
Wottensprels

Reputation: 3327

Injecting a provider into a module config

I have a provider named TestProvider

I'd like to configure my provider for my module.

This works:

app.config(function(testProviderProvider){
  // ...
}

This works not:

app.config(function(testProvider){
  // ...
}

I am injecting the same provider into a controller and it works:

function TestCtrl($scope,testProvider){
  // ..
}

WTF?

Upvotes: 3

Views: 79

Answers (1)

ardentum-c
ardentum-c

Reputation: 1410

From official docs:

provider(name, provider)

Register a provider for a service. The providers can be retrieved and can have additional configuration methods.

Parameters
name – {string} – The name of the instance. NOTE: the provider will be available under name + 'Provider' key.

You should name your provider without "Provider" word. This code works fine:

myApp.provider('test', function () {

});

myApp.config(function (testProvider) {

});

Upvotes: 2

Related Questions