Reputation: 5568
I know (and correct me if I'm wrong) that Angular's bootstrap procedure of angular.module('a', ['b', 'c'])
is:
b
and c
.a
.The bootstrap is a 3-steps procedure:
Each step occurs first on the dependencies b, c
and then on a
-- then moving to the next step.
Where did I mistake in the above description?
As this plunker shows that a
can depend on b
while b
depends on a
(it actually works), then it follows that my description is falsy, since each module bootstraps its dependencies before bootstraping itself.
Can you help?
Upvotes: 2
Views: 987
Reputation: 21229
Angular uses delayed execution for modules, which works differently from how you assume.
Each module is defined with a set of dependencies, but nothing is "executed" (in terms of function calls). The program is then executed after all modules are defined.
Your assumption: A depends on B, so it executes B first. But B depends on A, so it becomes impossible to load A or B.
Actual: Module A is created, with dependency B. Module B is created, with dependency A. At the time of execution, all dependencies are met since both A and B exist.
For config and run blocks:
[...] the configuration blocks of the required modules execute before the configuration blocks of the requiring module. The same is true for the run blocks. Each module can only be loaded once, even if multiple other modules require it.
In practice, this works similarly to a stack (with no duplicates). In the example of A and B, A is added to the stack first, then its dependency B. Since B depends on A and A is already in the stack, nothing is added. Thus, the config blocks of are run in order B, A. Then the run blocks are run in the same order.
See https://docs.angularjs.org/guide/module for more info.
Upvotes: 5