@@ -20,11 +20,18 @@ block includes
20
20
In the [Dependency Injection](./dependency-injection.html) guide,
21
21
you learned how to configure a dependency injector and how to retrieve dependencies where you need them.
22
22
23
- In fact, there is no such thing as *the* injector.
23
+ In fact, there is no such thing as *** the** * injector.
24
24
An application may have multiple injectors.
25
- An Angular application is a tree of components. Each component instance has its own injector!
25
+ An Angular application is a tree of components. Each component instance has its own injector.
26
26
The tree of components parallels the tree of injectors.
27
27
28
+ .l-sub-section
29
+ :marked
30
+ The component's injector may be a _proxy_ for an ancestor injector higher in the component tree.
31
+ That's an implementation detail that improves efficiency.
32
+ You won't notice the difference and
33
+ your mental model should be that every component has its own injector.
34
+
28
35
:marked
29
36
Consider this guide's variation on the Tour of Heroes application.
30
37
At the top is the `AppComponent` which has some sub-components.
@@ -37,14 +44,6 @@ figure.image-display
37
44
img( src ="/resources/images/devguide/dependency-injection/component-hierarchy.png" alt ="injector tree" width ="600" )
38
45
39
46
:marked
40
- Angular doesn't actually _create_ a separate injector for each component.
41
- Every component doesn't need its own injector and it would be horribly inefficient to create
42
- masses of injectors for no good purpose.
43
-
44
- But every component _has an injector_, even if it shares that injector with another component or with the injector of the root `AppModule`.
45
- And there _may_ be multiple injector instances operating at different levels of the component tree
46
- depending upon how the developer registers providers, which is the subject of this guide.
47
-
48
47
### Injector bubbling
49
48
50
49
When a component requests a dependency, Angular tries to satisfy that dependency with a provider registered in that component's own injector.
0 commit comments