@@ -46,7 +46,7 @@ figure.image-display
46
46
:marked
47
47
## Where We Left Off
48
48
49
- Before we continue with our Tour of Heroes, let’s verify that
49
+ Before we continue with our Tour of Heroes, let’s verify that
50
50
we have the following structure after adding our hero service
51
51
and hero detail component. If not, we’ll need to go back and follow the previous chapters.
52
52
@@ -105,7 +105,7 @@ block keep-app-running
105
105
106
106
Our current app loads `AppComponent` and immediately displays the list of heroes.
107
107
108
- Our revised app should present a shell with a choice of views (*Dashboard* and *Heroes*)
108
+ Our revised app should present a shell with a choice of views (*Dashboard* and *Heroes*)
109
109
and then default to one of them.
110
110
111
111
The `AppComponent` should only handle navigation.
@@ -135,9 +135,9 @@ block keep-app-running
135
135
* Create the file <span ngio-ex>app/app.component.ts</span>.
136
136
* Define an <span if-docs="ts">exported</span> `AppComponent` class.
137
137
* Add an `@Component` !{_decorator} above the class with a `my-app` selector.
138
- * Move from `HeroesComponent` to `AppComponent` the
139
- * `title` class property, and
140
- * `@Component` template `<h1>` element containing a `title` binding.
138
+ * Move the following from `HeroesComponent` to `AppComponent`:
139
+ * `title` class property
140
+ * `@Component` template `<h1>` element, which contains a binding to `title`
141
141
* Add a `<my-heroes>` element to the app template just below the heading so we still see the heroes.
142
142
* Add `HeroesComponent` to the `!{_declsVsDirectives}` !{_array} of `!{_AppModuleVsAppComp}` so Angular recognizes the `<my-heroes>` tags.
143
143
* Add `HeroService` to the `providers` !{_array} of `!{_AppModuleVsAppComp}` because we'll need it in every other view.
@@ -171,8 +171,8 @@ block app-comp-v1
171
171
block angular-router
172
172
:marked
173
173
The Angular router is an external, optional Angular NgModule called `RouterModule`.
174
- The router is a combination of multiple provided services (`RouterModule`),
175
- multiple directives (`RouterOutlet, RouterLink, RouterLinkActive`),
174
+ The router is a combination of multiple provided services (`RouterModule`),
175
+ multiple directives (`RouterOutlet, RouterLink, RouterLinkActive`),
176
176
and a configuration (`Routes`). We'll configure our routes first.
177
177
178
178
:marked
@@ -185,7 +185,7 @@ block angular-router
185
185
.callout.is-important
186
186
header base href is essential
187
187
:marked
188
- See the *base href* section of the [Router](../guide/router.html#!#base-href)
188
+ See the *base href* section of the [Router](../guide/router.html#!#base-href)
189
189
chapter to learn why this matters.
190
190
191
191
a#configure-routes
@@ -213,7 +213,7 @@ block router-config-intro
213
213
This *route definition* has the following parts:
214
214
215
215
- **path**: the router matches this route's path to the URL in the browser address bar (`/heroes`).
216
- <li if-docs="dart"> **name**: the official name of the route;
216
+ <li if-docs="dart"> **name**: the official name of the route;
217
217
it *must* begin with a capital letter to avoid confusion with the *path* (`Heroes`).</li>
218
218
- **component**: the component that the router should create when navigating to this route (`HeroesComponent`).
219
219
@@ -315,7 +315,7 @@ block routerLink
315
315
316
316
Go back to `!{_appRoutingTsVsAppComp}` and teach it to navigate to the dashboard.
317
317
318
- Import `DashboardComponent` and
318
+ Import the dashboard component and
319
319
add the following route definition to the `!{_RoutesVsAtRouteConfig}` !{_array} of definitions.
320
320
321
321
- var _file = _docsFor == ' dart' ? ' lib/app_component.dart' : ' app/app.routing.ts'
@@ -346,6 +346,8 @@ block redirect-vs-use-as-default
346
346
Learn about the *redirects* in the [Routing](../guide/router.html#!#redirect) chapter.
347
347
348
348
:marked
349
+ #### Add navigation to the template
350
+
349
351
Finally, add a dashboard navigation link to the template, just above the *Heroes* link.
350
352
351
353
- var _vers = _docsFor == ' dart' ? ' ' : ' .1'
@@ -443,7 +445,7 @@ block redirect-vs-use-as-default
443
445
The new route is a bit unusual in that we must tell the `HeroDetailComponent` *which hero to show*.
444
446
We didn't have to tell the `HeroesComponent` or the `DashboardComponent` anything.
445
447
446
- At the moment the parent `HeroesComponent` sets the component's `hero` property to a
448
+ At the moment the parent `HeroesComponent` sets the component's `hero` property to a
447
449
hero object with a binding like this.
448
450
449
451
code-example( language ="html" ) .
@@ -455,7 +457,7 @@ code-example(language="html").
455
457
456
458
### Parameterized route
457
459
458
- We *can* add the hero's `id` to the URL. When routing to the hero whose `id` is 11,
460
+ We *can* add the hero's `id` to the URL. When routing to the hero whose `id` is 11,
459
461
we could expect to see an URL such as this:
460
462
461
463
code-example( format ='' ) .
@@ -475,9 +477,10 @@ code-example(format='').
475
477
:marked
476
478
The colon (:) in the path indicates that `:id` is a placeholder to be filled with a specific hero `id`
477
479
when navigating to the `HeroDetailComponent`.
480
+
478
481
.l-sub-section
479
482
:marked
480
- Remember to import `HeroDetailComponent` before creating this route.
483
+ Remember to import the hero detail component before creating this route.
481
484
482
485
+ ifDocsFor('ts|js' )
483
486
:marked
@@ -517,15 +520,15 @@ block route-params
517
520
in the `ActivatedRoute` service and use the `HeroService` to fetch the hero with that `id`.
518
521
519
522
:marked
520
- Add requisite imports first :
523
+ First, add the requisite imports:
521
524
522
525
- var _vers = _docsFor == ' dart' ? ' ' : ' .1'
523
526
+ makeExcerpt('app/hero-detail.component' + _vers + '.ts' , 'added-imports' , '' )
524
527
525
528
- var _ActivatedRoute = _docsFor == ' dart' ? ' RouteParams' : ' ActivatedRoute'
526
529
:marked
527
530
Let's have the `!{_ActivatedRoute}` service and the `HeroService` injected
528
- into the constructor with their values saved in private fields:
531
+ into the constructor, saving their values in private fields:
529
532
530
533
+ makeExcerpt('app/hero-detail.component.ts (constructor)' , 'ctor' )
531
534
@@ -574,6 +577,9 @@ block extract-id
574
577
575
578
+ makeExcerpt('app/hero-detail.component.ts' , 'goBack' )
576
579
580
+ block dart-html
581
+ //- N/A
582
+
577
583
- var _CanDeactivateGuard = _docsFor == ' dart' ? ' <em>routerCanDeactivate</em> hook' : ' <em>CanDeactivate</em> guard'
578
584
- var _CanDeactivateGuardUri = _docsFor == ' dart' ? ' angular2.router/CanDeactivate-class' : ' router/index/CanDeactivate-interface'
579
585
.l-sub-section
@@ -589,8 +595,9 @@ block extract-id
589
595
+ makeExcerpt('app/hero-detail.component.html' , 'back-button' , '' )
590
596
591
597
:marked
592
- Modifing the template to add this button spurs us to take one more
593
- incremental improvement and migrate the template to its own file:
598
+ Modifing the template to add this button spurs us to take one more
599
+ incremental improvement and migrate the template to its own file,
600
+ called <span ngio-ex>hero-detail.component.html</span>:
594
601
595
602
+ makeExcerpt('app/hero-detail.component.html' )
596
603
@@ -601,10 +608,6 @@ block extract-id
601
608
602
609
:marked
603
610
Refresh the browser and see the results.
604
- Here's the (nearly) finished `HeroDetailComponent` but without the `@Input` !{_decorator} on `hero`
605
- — we'll be cleaning that out soon:
606
-
607
- + makeExcerpt('app/hero-detail.component.ts' , 'v2' )
608
611
609
612
.l-main-section
610
613
:marked
@@ -725,7 +728,7 @@ figure.image-display
725
728
:marked
726
729
The `styleUrls` property is !{_an} !{_array} of style file names (with paths).
727
730
We could list multiple style files from different locations if we needed them.
728
- <span if-docs="ts">As with `templateUrl`, we must specify the path _all the way
731
+ <span if-docs="ts">As with `templateUrl`, we must specify the path _all the way
729
732
back to the application root_.</span>
730
733
731
734
block heroes-component-cleanup
@@ -777,10 +780,10 @@ block heroes-component-cleanup
777
780
778
781
:marked
779
782
### Stylish Hero Details
780
-
783
+
781
784
The designers also gave us CSS styles specifically for the `HeroDetailComponent`.
782
785
783
- Add a <span ngio-ex>hero-detail.component.css</span> to the `!{_appDir}`
786
+ Add a <span ngio-ex>hero-detail.component.css</span> to the `!{_appDir}`
784
787
folder and refer to that file inside
785
788
the `styleUrls` !{_array} as we did for `DashboardComponent`.
786
789
Let's also remove the `hero` property `@Input` !{_decorator}
@@ -891,7 +894,7 @@ block file-tree-end
891
894
.file index.html
892
895
.file package.json
893
896
.file styles.css
894
- .file systemjs.config.json
897
+ .file systemjs.config.js
895
898
.file tsconfig.json
896
899
.file typings.json
897
900
0 commit comments