This got me curious so I did some research. Here is what I found:
- $injector cannot be injected into config blocks
- $provide can be injected into config blocks
In code, the reason for 2 is that $provide
is put into the providerCache
before the providerInjector
(the injector used in config blocks) is created. This ensures that it will always be a known provider to the providerInjector
. https://github.com/angular/angular.js/blob/master/src/auto/injector.js#L671
That said, I do agree that being able inject $provide
into config blocks seems to contradict the general rule regarding what can be injected into configuration blocks stated here: https://docs.angularjs.org/guide/module#module-loading-dependencies
Even though it is clearly demonstrated to be something you can do here:
https://docs.angularjs.org/guide/module#configuration-blocks
$provide
might just be the one exception to the general rule.