Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 265
Wottensprels Avatar asked Nov 26 '25 05:11

Wottensprels


1 Answers

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) {

});
like image 119
ardentum-c Avatar answered Nov 27 '25 19:11

ardentum-c



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!