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

Commit a705a0c

Browse files
kapunahelewongwardbell
authored andcommitted
docs(toh): copy edit and fixes in 4, 5, 6 and example (#3412)
1 parent 56c8706 commit a705a0c

File tree

5 files changed

+110
-94
lines changed

5 files changed

+110
-94
lines changed

public/docs/_examples/toh-5/ts/src/app/hero-detail.component.1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// is solely for containing the transitory state of the imports.
44

55
// #docregion added-imports
6-
// Keep the Input import for now, we'll remove it later:
6+
// Keep the Input import for now, you'll remove it later:
77
import { Component, Input, OnInit } from '@angular/core';
88
import { ActivatedRoute, Params } from '@angular/router';
99
import { Location } from '@angular/common';

public/docs/_examples/toh-5/ts/src/app/heroes.component.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* #docregion */
12
.selected {
23
background-color: #CFD8DC !important;
34
color: white;

public/docs/ts/latest/tutorial/toh-pt4.jade

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ code-example(language="sh" class="code-shell").
9292

9393
:marked
9494
### Getting hero data
95-
Add a `getHeroes` method stub.
95+
Add a `getHeroes()` method stub.
9696

9797
+makeExample('toh-4/ts/src/app/hero.service.1.ts', 'getHeroes-stub', 'src/app/hero.service.ts (getHeroes stub)')(format=".")
9898

@@ -117,7 +117,7 @@ code-example(language="sh" class="code-shell").
117117
+makeExample('toh-4/ts/src/app/app.component.1.ts', 'heroes-prop', 'src/app/app.component.ts (heroes property)')(format=".")
118118
:marked
119119
### Return mocked hero data
120-
Back in the `HeroService`, import the mock `HEROES` and return it from the `getHeroes` method.
120+
Back in the `HeroService`, import the mock `HEROES` and return it from the `getHeroes()` method.
121121
The `HeroService` looks like this:
122122
+makeExample('toh-4/ts/src/app/hero.service.1.ts', 'full', 'src/app/hero.service.ts')(format=".")
123123

@@ -184,7 +184,7 @@ code-example(format="nocode").
184184
The `AppComponent`, as well as its child components, can use that service to get hero data.
185185
a#child-component
186186
:marked
187-
### *getHeroes* in the *AppComponent*
187+
### *getHeroes()* in the *AppComponent*
188188
The service is in a `heroService` private variable.
189189

190190
You could call the service and get the data in one line.
@@ -198,12 +198,12 @@ a#child-component
198198
### The *ngOnInit* lifecycle hook
199199
`AppComponent` should fetch and display hero data with no issues.
200200

201-
You might be tempted to call the `getHeroes` method in a constructor, but
201+
You might be tempted to call the `getHeroes()` method in a constructor, but
202202
a constructor should not contain complex logic,
203203
especially a constructor that calls a server, such as as a data access method.
204204
The constructor is for simple initializations, like wiring constructor parameters to properties.
205205

206-
To have Angular call `getHeroes`, you can implement the Angular *ngOnInit lifecycle hook*.
206+
To have Angular call `getHeroes()`, you can implement the Angular *ngOnInit lifecycle hook*.
207207
Angular offers interfaces for tapping into critical moments in the component lifecycle:
208208
at creation, after each change, and at its eventual destruction.
209209

@@ -221,7 +221,7 @@ code-example(format="nocode").
221221
export class AppComponent implements OnInit {}
222222
:marked
223223
Write an `ngOnInit` method with the initialization logic inside. Angular will call it
224-
at the right time. In this case, initialize by calling `getHeroes`.
224+
at the right time. In this case, initialize by calling `getHeroes()`.
225225
+makeExcerpt('toh-4/ts/src/app/app.component.1.ts', 'ng-on-init', 'app/app.component.ts')
226226
:marked
227227
The app should run as expected, showing a list of heroes and a hero detail view
@@ -231,15 +231,17 @@ code-example(format="nocode").
231231
:marked
232232
## Async services and !{_Promise}s
233233
The `HeroService` returns a list of mock heroes immediately;
234-
its `getHeroes` signature is synchronous.
234+
its `getHeroes()` signature is synchronous.
235235
+makeExample('toh-4/ts/src/app/app.component.1.ts', 'get-heroes')(format=".")
236236
:marked
237237
Eventually, the hero data will come from a remote server.
238-
When using the remote server, users don't have to wait for the server to respond
239-
and you aren't able to block the UI during the wait.
238+
When using a remote server, users don't have to wait for the server to respond;
239+
additionally, you aren't able to block the UI during the wait.
240240

241241
:marked
242-
Instead, you can use *!{_Promise}s*, which is an asynchronous technique that changes the signature of the `getHeroes` method.
242+
To coordinate the view with the response,
243+
you can use *!{_Promise}s*, which is an asynchronous
244+
technique that changes the signature of the `getHeroes()` method.
243245

244246
### The hero service makes a !{_Promise}
245247

@@ -253,7 +255,7 @@ code-example(format="nocode").
253255
[Exploring ES6](http://http://exploringjs.com/es6.html).
254256

255257
:marked
256-
Update the `HeroService` with this !{_Promise}-returning `getHeroes` method:
258+
Update the `HeroService` with this !{_Promise}-returning `getHeroes()` method:
257259
+makeExample('toh-4/ts/src/app/hero.service.ts', 'get-heroes', 'src/app/hero.service.ts (excerpt)')(format=".")
258260
:marked
259261
You're still mocking the data. You're simulating the behavior of an ultra-fast, zero-latency server,
@@ -268,7 +270,7 @@ code-example(format="nocode").
268270
You have to change the implementation to *act on the !{_Promise} when it resolves*.
269271
When the !{_Promise} resolves successfully, you'll have heroes to display.
270272

271-
Pass the callback function as an argument to the !{_Promise}'s `then` method:
273+
Pass the callback function as an argument to the !{_Promise}'s `then()` method:
272274
+makeExample('toh-4/ts/src/app/app.component.ts', 'get-heroes', 'src/app/app.component.ts (getHeroes - revised)')(format=".")
273275
.l-sub-section
274276
:marked
@@ -334,20 +336,20 @@ code-example(format="nocode").
334336
## The road ahead
335337
The Tour of Heroes has become more reusable using shared components and services.
336338
The next goal is to create a dashboard, add menu links that route between the views, and format data in a template.
337-
As the app evolves, you'll learn how to design it to make it easier to grow and maintain.
339+
As the app evolves, you'll discover how to design it to make it easier to grow and maintain.
338340

339-
You learn about Angular component router and navigation among the views in the [next tutorial](toh-pt5.html) page.
341+
Read about the Angular component router and navigation among the views in the [next tutorial](toh-pt5.html) page.
340342

341343
.l-main-section
342344
<a id="slow"></a>
343345
:marked
344346
## Appendix: Take it slow
345347
To simulate a slow connection,
346-
import the `Hero` symbol and add the following `getHeroesSlowly` method to the `HeroService`.
348+
import the `Hero` symbol and add the following `getHeroesSlowly()` method to the `HeroService`.
347349
+makeExample('toh-4/ts/src/app/hero.service.ts', 'get-heroes-slowly', 'app/hero.service.ts (getHeroesSlowly)')(format=".")
348350
:marked
349-
Like `getHeroes`, it also returns a !{_Promise}.
351+
Like `getHeroes()`, it also returns a !{_Promise}.
350352
But this !{_Promise} waits two seconds before resolving the !{_Promise} with mock heroes.
351353

352-
Back in the `AppComponent`, replace `heroService.getHeroes` with `heroService.getHeroesSlowly`
354+
Back in the `AppComponent`, replace `getHeroes()` with `getHeroesSlowly()`
353355
and see how the app behaves.

public/docs/ts/latest/tutorial/toh-pt5.jade

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ block includes
1212

1313
* Add a *Dashboard* view.
1414
* Add the ability to navigate between the *Heroes* and *Dashboard* views.
15-
* When users click a hero name in either view, they should navigate to a detail view of the selected hero.
16-
* When users click a *deep link* in an email, the detail view for a particular hero should open.
15+
* When users click a hero name in either view, navigate to a detail view of the selected hero.
16+
* When users click a *deep link* in an email, open the detail view for a particular hero.
1717

1818
When you’re done, users will be able to navigate the app like this:
1919

@@ -37,7 +37,6 @@ figure.image-display
3737
:marked
3838
## Where you left off
3939
Before continuing with the Tour of Heroes, verify that you have the following structure.
40-
If not, go back to the previous pages.
4140

4241
block intro-file-tree
4342
.filetree
@@ -215,14 +214,14 @@ block router-config-intro
215214
:marked
216215
### Make the router available
217216

218-
Add the initial route configuration, `RouterModule`, to the `AppModule` imports !{_array}.
217+
Import the `RouterModule` and add it to the `AppModule` imports !{_array}.
219218

220219
+makeExcerpt('src/app/app.module.2.ts (app routing)', '')
221220

222221
.l-sub-section
223222
:marked
224-
The `forRoot` method is called because a configured router is provided at the app's root.
225-
The `forRoot` method supplies the Router service providers and directives needed for routing, and
223+
The `forRoot()` method is called because a configured router is provided at the app's root.
224+
The `forRoot()` method supplies the Router service providers and directives needed for routing, and
226225
performs the initial navigation based on the current browser URL.
227226

228227
- var _heroesRoute = _docsFor == 'dart' ? "'Heroes'" : 'heroes'
@@ -260,7 +259,7 @@ block routerLink
260259
[Routing & Navigation](../guide/router.html#) page.
261260

262261
:marked
263-
Refresh the browser. The app title and heroes link, but not the heroes list, display.
262+
Refresh the browser. The browser displays the app title and heroes link, but not the heroes list.
264263

265264
.l-sub-section
266265
:marked
@@ -269,7 +268,7 @@ block routerLink
269268
Soon you'll add a route that matches the path `/`.
270269

271270
:marked
272-
Click the *Heroes* navigation link. The browser bar updates to `/heroes`
271+
Click the *Heroes* navigation link. The address bar updates to `/heroes`
273272
and the list of heroes displays.
274273

275274
`AppComponent` now looks like this:
@@ -361,13 +360,13 @@ block templateUrl-path-resolution
361360

362361
:marked
363362
`*ngFor` is used again to iterate over a list of heroes and display their names.
364-
The extra `<div>` elements will help with styling later in this page.
363+
The extra `<div>` elements will help with styling later.
365364

366365
### Sharing the *HeroService*
367366

368367
To populate the component's `heroes` !{_array}, you can re-use the `HeroService`.
369368

370-
Earlier in the page, you removed the `HeroService` from the `providers` !{_array} of `HeroesComponent`
369+
Earlier, you removed the `HeroService` from the `providers` !{_array} of `HeroesComponent`
371370
and added it to the `providers` !{_array} of `!{_AppModuleVsAppComp}`.
372371
That move created a singleton `HeroService` instance, available to all components of the app.
373372
Angular injects `HeroService` and you can use it in the `DashboardComponent`.
@@ -379,7 +378,7 @@ block templateUrl-path-resolution
379378
+makeExcerpt('src/app/dashboard.component.ts','imports')
380379

381380
:marked
382-
Now implement the `DashboardComponent` class like this:
381+
Now create the `DashboardComponent` class like this:
383382

384383
+makeExcerpt('src/app/dashboard.component.ts (class)', 'class')
385384

@@ -474,7 +473,7 @@ code-example(format="nocode").
474473
block route-params
475474
:marked
476475
You'll no longer receive the hero in a parent component property binding.
477-
The new `HeroDetailComponent` should take the `id` parameter from the `params` observable
476+
The new `HeroDetailComponent` should take the `id` parameter from the `params` Observable
478477
in the `ActivatedRoute` service and use the `HeroService` to fetch the hero with that `id`.
479478

480479
:marked
@@ -505,7 +504,7 @@ block route-params
505504

506505
block ngOnInit
507506
:marked
508-
Inside the `ngOnInit` lifecycle hook, use the `params` observable to
507+
Inside the `ngOnInit` lifecycle hook, use the `params` Observable to
509508
extract the `id` parameter value from the `ActivatedRoute` service
510509
and use the `HeroService` to fetch the hero with that `id`.
511510

@@ -514,11 +513,11 @@ block ngOnInit
514513

515514
block extract-id
516515
:marked
517-
The `switchMap` operator maps the id in the observable route parameters
518-
to a new `Observable`, the result of the `HeroService.getHero` method.
516+
The `switchMap` operator maps the `id` in the Observable route parameters
517+
to a new `Observable`, the result of the `HeroService.getHero()` method.
519518

520-
If a user re-navigates to this component while a getHero request is still processing,
521-
`switchMap` cancels the old request and then calls `HeroService.getHero` again.
519+
If a user re-navigates to this component while a `getHero` request is still processing,
520+
`switchMap` cancels the old request and then calls `HeroService.getHero()` again.
522521

523522
- var _str2int = _docsFor == 'dart' ? '<code>int.parse</code> static method' : 'JavaScript (+) operator'
524523
:marked
@@ -534,13 +533,13 @@ block extract-id
534533
section of the [Routing & Navigation](../guide/router.html) page,
535534
the `Router` manages the observables it provides and localizes
536535
the subscriptions. The subscriptions are cleaned up when the component is destroyed, protecting against
537-
memory leaks, so you don't need to unsubscribe from the route params `Observable`.
536+
memory leaks, so you don't need to unsubscribe from the route `params` `Observable`.
538537

539538
:marked
540539
### Add *HeroService.getHero*
541540

542-
In the previous code snippet, `HeroService` doesn't have a `getHero` method. To fix this issue,
543-
open `HeroService` and add a `getHero` method that filters the heroes list from `getHeroes` by `id`.
541+
In the previous code snippet, `HeroService` doesn't have a `getHero()` method. To fix this issue,
542+
open `HeroService` and add a `getHero()` method that filters the heroes list from `getHeroes` by `id`.
544543

545544
+makeExcerpt('src/app/hero.service.ts', 'getHero')
546545

@@ -550,7 +549,7 @@ block extract-id
550549
Users have several ways to navigate *to* the `HeroDetailComponent`.
551550

552551
To navigate somewhere else, users can click one of the two links in the `AppComponent` or click the browser's back button.
553-
Now add a third option, a `goBack` method that navigates backward one step in the browser's history stack
552+
Now add a third option, a `goBack()` method that navigates backward one step in the browser's history stack
554553
using the `Location` service you injected previously.
555554

556555
+makeExcerpt('src/app/hero-detail.component.ts', 'goBack')
@@ -633,8 +632,8 @@ block extract-id
633632
establish key facts about the entire app for the Angular compiler.
634633

635634
It's a good idea to refactor the routing configuration into its own class.
636-
The current `RouterModule.forRoot()` produces an Angular `ModuleWithProviders`.
637-
A class dedicated to routing should be a *routing module*.
635+
The current `RouterModule.forRoot()` produces an Angular `ModuleWithProviders`,
636+
a class dedicated to routing should be a *routing module*.
638637
For more information, see the [Milestone #2: The Routing Module](../guide/router.html#routing-module)
639638
section of the [Routing & Navigation](../guide/router.html) page.
640639

@@ -658,8 +657,8 @@ block extract-id
658657

659658
### Update *AppModule*
660659

661-
Delete the routing configuration from `AppModule` and import the `AppRoutingModule`
662-
(*both* with an ES `import` statement *and* by adding it to the `NgModule.imports` list).
660+
Delete the routing configuration from `AppModule` and import the `AppRoutingModule`.
661+
Use an ES `import` statement *and* add it to the `NgModule.imports` list.
663662

664663
:marked
665664
Here is the revised `AppModule`, compared to its pre-refactor state:
@@ -696,9 +695,6 @@ block extract-id
696695

697696
Add the following HTML fragment at the bottom of the template where the `<hero-detail>` used to be:
698697

699-
700-
Add the following HTML fragment at the bottom of the template where the `<my-hero-detail>` used to be:
701-
702698
+makeExcerpt('src/app/heroes.component.html', 'mini-detail', 'src/app/heroes.component.ts')
703699

704700

@@ -733,41 +729,56 @@ figure.image-display
733729
The component file is big.
734730
It's difficult to find the component logic amidst the noise of HTML and CSS.
735731

736-
Before making any more changes, migrate the template and styles to their own files.
732+
Before making any more changes, migrate the template and styles to their own files.
737733

738-
1. *Cut-and-paste* the template contents into a new <span ngio-ex>heroes.component.html</span> file.
739-
1. *Cut-and-paste* the styles contents into a new <span ngio-ex>heroes.component.css</span> file.
740-
1. *Set* the component metadata's `templateUrl` and `styleUrls` properties to refer to both files.
734+
First, move the template contents from `heroes.component.ts`
735+
into a new <span ngio-ex>heroes.component.html</span> file.
736+
Don't copy the backticks. As for `heroes.component.ts`, you'll
737+
come back to it in a minute. Next, move the
738+
styles contents into a new <span ngio-ex>heroes.component.css</span> file.
741739

742-
.l-sub-section
743-
:marked
744-
The `styleUrls` property is !{_an} !{_array} of style file names (with paths).
745-
You could list multiple style files from different locations if you needed them.
740+
The two new files should look like this:
741+
742+
+makeTabs(
743+
`toh-5/ts/src/app/heroes.component.html, toh-5/ts/src/app/heroes.component.css`,
744+
null,
745+
`src/app/heroes.component.html, src/app/heroes.component.css`)
746+
747+
:marked
748+
Now, back in the component metadata for `heroes.component.ts`,
749+
delete `template` and `styles`, replacing them with
750+
`templateUrl` and `styleUrls` respectively.
751+
Set their properties to refer to the new files.
746752

747753
block heroes-component-cleanup
748754
//- Only relevant for Dart.
749755
750756
+makeExcerpt('src/app/heroes.component.ts (revised metadata)', 'metadata')
751757

758+
.l-sub-section
759+
:marked
760+
The `styleUrls` property is !{_an} !{_array} of style file names (with paths).
761+
You could list multiple style files from different locations if you needed them.
762+
752763
:marked
753764
### Update the _HeroesComponent_ class
754765

755766
The `HeroesComponent` navigates to the `HeroesDetailComponent` in response to a button click.
756-
The button's click event is bound to a `gotoDetail` method that navigates _imperatively_
767+
The button's click event is bound to a `gotoDetail()` method that navigates _imperatively_
757768
by telling the router where to go.
758769

759770
This approach requires the following changes to the component class:
760771

761772
1. Import the `router` from the Angular router library.
762-
1. Inject the `router` in the constructor (along with the `HeroService`).
763-
1. Implement `gotoDetail` by calling the `router.navigate` method.
773+
1. Inject the `router` in the constructor, along with the `HeroService`.
774+
1. Implement `gotoDetail()` by calling the `router.navigate()` method.
764775

765776
+makeExcerpt('src/app/heroes.component.ts', 'gotoDetail')
766777

767778
:marked
768779
Note that you're passing a two-element *link parameters !{_array}*&mdash;a
769780
path and the route parameter&mdash;to
770-
the `router.navigate` method, just as you did in the `[routerLink]` binding
781+
the `router.navigate()` method, just as you did in the `[routerLink]` binding
771782
back in the `DashboardComponent`.
772783
Here's the revised `HeroesComponent` class:
773784

@@ -788,7 +799,7 @@ block heroes-component-cleanup
788799
The dashboard heroes should display in a row of rectangles.
789800
You've received around 60 lines of CSS for this purpose, including some simple media queries for responsive design.
790801

791-
Adding the CSS to the component `styles` metadata
802+
As you now know, adding the CSS to the component `styles` metadata
792803
would obscure the component logic.
793804
Instead, edit the CSS in a separate `*.css` file.
794805

@@ -805,7 +816,7 @@ block heroes-component-cleanup
805816
Add a <span ngio-ex>hero-detail.component.css</span> to the `!{_appDir}`
806817
folder and refer to that file inside
807818
the `styleUrls` !{_array} as you did for `DashboardComponent`.
808-
Also, in hero-detail.component.ts, remove the `hero` property `@Input` !{_decorator}
819+
Also, in `hero-detail.component.ts`, remove the `hero` property `@Input` !{_decorator}
809820
<span if-docs="ts">and its import</span>.
810821

811822
Here's the content for the component CSS files.

0 commit comments

Comments
 (0)