@@ -56,10 +56,11 @@ figure.image-display
5656 :marked
5757 You can cap the bubbling. An intermediate component can declare that it is the "host" component.
5858 The hunt for providers will climb no higher than the injector for that host component.
59- This a topic for another day.
59+ This is a topic for another day.
6060
6161:marked
6262 ### Re-providing a service at different levels
63+
6364 You can re-register a provider for a particular dependency token at multiple levels of the injector tree.
6465 You don't *have* to re-register providers. You shouldn't do so unless you have a good reason.
6566 But you *can*.
@@ -77,7 +78,6 @@ figure.image-display
7778
7879 The ability to configure one or more providers at different levels opens up interesting and useful possibilities.
7980
80- :marked
8181 ### Scenario: service isolation
8282
8383 Architectural reasons may lead you to restrict access to a service to the application domain where it belongs.
@@ -93,9 +93,10 @@ figure.image-display
9393
9494 Instead, provide the `VillainsService` in the `providers` metadata of the `VillainsListComponent` like this:
9595
96- + makeExample('hierarchical-dependency-injection/ts/src/app/villains-list.component.ts' , 'metadata' ,'src/app/villains-list.component.ts (metadata)' )( format ='.' )
96+ + makeExcerpt('src/app/villains-list.component.ts (metadata)' )
97+
9798:marked
98- By providing `VillainsService` in the `VillainsListComponent` metadata — and nowhere else —,
99+ By providing `VillainsService` in the `VillainsListComponent` metadata and nowhere else,
99100 the service becomes available only in the `VillainsListComponent` and its sub-component tree.
100101 It's still a singleton, but it's a singleton that exist solely in the _villain_ domain.
101102
@@ -120,20 +121,23 @@ figure.image-display
120121
121122figure.image-display
122123 img( src ="/resources/images/devguide/dependency-injection/hid-heroes-anim.gif" width ="400" alt ="Heroes in action" )
124+
123125:marked
124- One might suppose that the `TaxReturnComponent ` has logic to manage and restore changes.
126+ One might suppose that the `HeroTaxReturnComponent ` has logic to manage and restore changes.
125127 That would be a pretty easy task for a simple hero tax return.
126128 In the real world, with a rich tax return data model, the change management would be tricky.
127129 You might delegate that management to a helper service, as this example does.
128130
129131 Here is the `HeroTaxReturnService`.
130132 It caches a single `HeroTaxReturn`, tracks changes to that return, and can save or restore it.
131133 It also delegates to the application-wide, singleton `HeroService`, which it gets by injection.
132- + makeExample('hierarchical-dependency-injection/ts/src/app/hero-tax-return.service.ts' , '' , 'src/app/hero-tax-return.service.ts' )
134+
135+ + makeExample('src/app/hero-tax-return.service.ts' )
133136
134137:marked
135138 Here is the `HeroTaxReturnComponent` that makes use of it.
136- + makeExample('hierarchical-dependency-injection/ts/src/app/hero-tax-return.component.ts' , null , 'src/app/hero-tax-return.component.ts' )
139+
140+ + makeExample('src/app/hero-tax-return.component.ts' )
137141
138142:marked
139143 The _tax-return-to-edit_ arrives via the input property which is implemented with getters and setters.
@@ -148,7 +152,8 @@ figure.image-display
148152
149153 Look closely at the metadata for the `HeroTaxReturnComponent`. Notice the `providers` property.
150154
151- + makeExample('hierarchical-dependency-injection/ts/src/app/hero-tax-return.component.ts' , 'providers' )
155+ + makeExcerpt('src/app/hero-tax-return.component.ts' , 'providers' , '' )
156+
152157:marked
153158 The `HeroTaxReturnComponent` has its own provider of the `HeroTaxReturnService`.
154159 Recall that every component _instance_ has its own injector.
@@ -194,7 +199,7 @@ figure.image-display
194199 :marked
195200 The code for this _cars_ scenario is in the `car.components.ts` and `car.services.ts` files of the sample
196201 which you can review and download from the <live-example></live-example>
197- : marked
202+
198203//- ## Advanced Dependency Injection in Angular
199204//- Restrict Dependency Lookups
200205//- [TODO] (@Host) This has been postponed for now until we come up with a decent use case
0 commit comments