We have answer of your question!

100% solved queries, no empty question

Question: Importance of order in registering provider and configuring a module in angular.js


it seems that from angular's point of view the order of registering of a service provider and the module configuration code is important: in order for the configuration code to find the provider, the provider should be registered before.

This was a total surprise for me, as I thought that angular first processes all provider registrations, to make them available for DI, and then calls config callbacks, like this:

module.config(function(myServiceProvider) {...});

Please see here a very short test that demonstrates the problem. It fails on "unknown provider", you can see it in the JS console: http://plnkr.co/edit/jGJmE2Fq7wOrwubdlTTX

Am I missing anything here? Is it an expected angular behavior?


Question author Stas | Source



Looks like this behavior has changed in more recent versions of Angular (not sure when exactly). I modified your Plunker to point from 1.0.7 to 1.3.0 and it worked without error as you had originally expected.

Similar example of code that works: var myModule = angular.module('myModule', []);

myModule.config((myServiceProvider) => {

myModule.service('myService', () => {

Running a config for a provider before the provider is registered with the module should work just fine as you were expecting.


For reference, this reported issue appears to be the one to have fixed it: https://github.com/angular/angular.js/issues/6723

Answer author Bingles

Tickanswer.com is providing the only single recommended solution of the question Importance of order in registering provider and configuring a module in angular.js under the categories i.e angularjs , . Our team of experts filter the best solution for you.

Related Search Queries:

You may also add your answer

Thanks for contributing an answer to Tick Answer!