Why does Angular allow you to embed the $ provision service in configuration blocks?

According to the Angular documentation, we can only enter providers (and not instances) into the configuration blocks. https://docs.angularjs.org/guide/module#module-loading-dependencies

But contrary to this, Angular allows you to enter $provide or $inject , despite the fact that they are instances of a single-user service.

https://docs.angularjs.org/api/auto/service/$provide

+5
source share
1 answer

I found this curious, so I did some research. Here is what I found:

  • $ injector cannot be entered into configuration blocks
  • $ provision can be inserted into configuration blocks

In code, reason 2 is that $provide is placed in providerCache before providerInjector (the injector used in configuration blocks) is created. This ensures that he will always be a renowned provider for providerInjector . https://github.com/angular/angular.js/blob/master/src/auto/injector.js#L671

However, I agree that the ability to enter $provide in configuration blocks seems to contradict the general rule regarding what can be entered in the configuration blocks specified here: https://docs.angularjs.org/guide/module#module- loading-dependencies

Despite the fact that what you can do here is clearly demonstrated: https://docs.angularjs.org/guide/module#configuration-blocks

$provide may be the only exception to the general rule.

+1
source

Source: https://habr.com/ru/post/1268721/


All Articles