Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit ffdf5ca

Browse files
chalinwardbell
authored andcommitted
docs(hier-dep-inj): fix comp name, spelling in field name, copyedits (#3335)
* docs(hier-dep-inj): fix in comp name, spelling in field name, copyedits - `villaines` --> `villains` - `TaxReturnComponent` --> `HeroTaxReturnComponent` - Moved `@Input()` to be on setter rather than getter. - Other misc copyedits
1 parent 55d43b0 commit ffdf5ca

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

public/docs/_examples/hierarchical-dependency-injection/ts/src/app/hero-tax-return.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ import { HeroTaxReturnService } from './hero-tax-return.service';
1515
export class HeroTaxReturnComponent {
1616
message = '';
1717
@Output() close = new EventEmitter<void>();
18-
@Input()
18+
1919
get taxReturn(): HeroTaxReturn {
2020
return this.heroTaxReturnService.taxReturn;
2121
}
22+
@Input()
2223
set taxReturn (htr: HeroTaxReturn) {
2324
this.heroTaxReturnService.taxReturn = htr;
2425
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div>
22
<h3>Villains</h3>
33
<ul>
4-
<li *ngFor="let villain of villaines | async">{{villain.name}}</li>
4+
<li *ngFor="let villain of villains | async">{{villain.name}}</li>
55
</ul>
66
</div>

public/docs/_examples/hierarchical-dependency-injection/ts/src/app/villains-list.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import { Villain, VillainsService } from './villains.service';
1313
})
1414
// #enddocregion metadata
1515
export class VillainsListComponent {
16-
villaines: Observable<Villain[]>;
16+
villains: Observable<Villain[]>;
1717

18-
constructor(private villainesService: VillainsService) {
19-
this.villaines = villainesService.getVillains();
18+
constructor(private villainsService: VillainsService) {
19+
this.villains = villainsService.getVillains();
2020
}
2121
}

public/docs/ts/latest/guide/hierarchical-dependency-injection.jade

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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 &mdash; and nowhere else &mdash;,
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

121122
figure.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

Comments
 (0)