AUTO basically wires up modules with $provide and $injector. The $injector references itself so $injector === $injector.get('$injector'). It avoids the chicken/egg scenario by building up the module outside of the Angular context and manually shoving the $injector and $provide into it. From that point forward the module can then use $provide, $injector, etc. You will never reference a module explicitly called "AUTO" but any module you create via angular.module will have an $injector and $provide. The other services come from the 'ng' module but the AUTO portion of it has to be built up so there is a DI container to use.
AngularJS - AUTO module and $injector
-
08-10-2022 - |
Question
On this page, the Angular docs describe the AUTO
module as:
Implicit module which gets automatically added to each $injector.
Yet, the $injector
is located inside this AUTO
module.
AUTO
$injector
AUTO
$injector ...
Clearly I'm missing something.
How does the AUTO
module relate to the angular.module()
, and where does the $injector
fit in?
angular.module()
AUTO
$injector
This would make sense, but then the docs that imply that AUTO
is added to $injector
doesn't make sense. I'm wondering if I'm misinterpreting something. So my question is, am I misinterpreting something?
Solution
OTHER TIPS
There are two injectors, an internal one, and an external one:
The instanceInjector stores the list of instantiated services in the system. It is initialized with an empty object. The providerInjector maintains the list of uninstantiated services.
The angular.injector
method can create an instance:
angular.injector().get("$injector")
The built-in module ng
can also:
angular.module("ng")._configBlocks[0][0]
References