@@ -205,7 +205,6 @@ block router-config-intro
205
205
206
206
- var _are = _docsFor == ' dart' ? ' takes' : ' are'
207
207
- var _routePathPrefix = _docsFor == ' dart' ? ' /' : ' '
208
-
209
208
:marked
210
209
The `!{_RoutesVsAtRouteConfig}` !{_are} !{_an} !{_array} of *route definitions*.
211
210
We have only one route definition at the moment but rest assured, we'll add more.
@@ -362,11 +361,15 @@ block redirect-vs-use-as-default
362
361
363
362
Replace the `template` metadata with a `templateUrl` property that points to a new
364
363
template file.
365
-
366
- Set the `moduleId` property to `module.id` for module-relative loading of the `templateUrl`.
364
+ + ifDocsFor('ts|js' )
365
+ :marked
366
+ Set the `moduleId` property to `module.id` for module-relative loading of the `templateUrl`.
367
367
368
368
+ makeExcerpt('app/dashboard.component.ts' , 'metadata' )
369
369
370
+ block templateUrl-path-resolution
371
+ //- N/A for TS
372
+
370
373
:marked
371
374
Create that file with this content:
372
375
@@ -404,7 +407,7 @@ block redirect-vs-use-as-default
404
407
* Inject the `HeroService` in the constructor and hold it in a private `!{_priv}heroService` field.
405
408
* Call the service to get heroes inside the Angular `ngOnInit` lifecycle hook.
406
409
407
- In this dashboard we cherry-pick four heroes (2nd, 3rd, 4th, and 5th) with the `Array.slice` method.
410
+ In this dashboard we cherry-pick four heroes (2nd, 3rd, 4th, and 5th)<span if-docs="ts"> with the `Array.slice` method</span> .
408
411
409
412
Refresh the browser and see four heroes in the new dashboard.
410
413
@@ -575,10 +578,10 @@ block extract-id
575
578
incremental improvement and migrate the template to its own file,
576
579
called <span ngio-ex>hero-detail.component.html</span>:
577
580
578
- + makeExample('app/hero-detail.component.html' )( format = '.' )
581
+ + makeExample('app/hero-detail.component.html' )
579
582
580
583
:marked
581
- We update the component metadata with a `moduleId` and a `templateUrl` pointing to the template file that we just created.
584
+ We update the component metadata with a <span if-docs="ts"> `moduleId` and a </span> `templateUrl` pointing to the template file that we just created.
582
585
583
586
+ makeExcerpt('app/hero-detail.component.ts' , 'metadata' )
584
587
@@ -600,11 +603,17 @@ block extract-id
600
603
601
604
+ makeExample('app/dashboard.component.html' , 'click' , 'app/dashboard.component.html (repeated <a> tag)' )
602
605
606
+ + ifDocsFor('dart' )
607
+ .alert.is-important
608
+ :marked
609
+ Router links in the dashboard are currently not operational, as reported in issue
610
+ [dart-lang/angular2/issues/186](https://github.com/dart-lang/angular2/issues/186).
611
+
603
612
- var _pathVsName = _docsFor == ' dart' ? ' name' : ' path'
604
613
:marked
605
614
Notice the `[routerLink]` binding.
606
615
607
- In the top level navigation in the [`AppComponent`
616
+ Top level navigation in the [`AppComponent`
608
617
template](#router-links) has router links set to fixed !{_pathVsName}s of the
609
618
destination routes, "/dashboard" and "/heroes".
610
619
@@ -622,53 +631,55 @@ block extract-id
622
631
:marked
623
632
Refresh the browser and select a hero from the dashboard; the app should navigate directly to that hero’s details.
624
633
625
- .l-main-section
626
- :marked
627
- ## Refactor routes to a _Routing Module_
634
+ + ifDocsFor('ts' )
635
+ .l-main-section
636
+ :marked
637
+ ## Refactor routes to a _Routing Module_
628
638
629
- Almost 20 lines of `AppModule` are devoted to configuring four routes.
630
- Most application have many more routes and they [add guard services](../guide/router.html#guards)
631
- to protect against unwanted or unauthorized navigations.
632
- Routing considerations could quickly dominate this module and obscure its primary purpose which is to
633
- establish key facts about the entire app for the Angular compiler.
639
+ Almost 20 lines of `AppModule` are devoted to configuring four routes.
640
+ Most applications have many more routes and they [add guard services](../guide/router.html#guards)
641
+ to protect against unwanted or unauthorized navigations.
642
+ Routing considerations could quickly dominate this module and obscure its primary purpose which is to
643
+ establish key facts about the entire app for the Angular compiler.
634
644
635
- We should refactor the routing configuration into its own class.
636
- What kind of class?
637
- The current `RouterModule.forRoot()` produces an Angular `ModuleWithProviders` which suggests that a
638
- class dedicated to routing should be some kind of module.
639
- It should be a [_Routing Module_](../guide/router.html#routing-module).
645
+ We should refactor the routing configuration into its own class.
646
+ What kind of class?
647
+ The current `RouterModule.forRoot()` produces an Angular `ModuleWithProviders` which suggests that a
648
+ class dedicated to routing should be some kind of module.
649
+ It should be a [_Routing Module_](../guide/router.html#routing-module).
640
650
641
- By convention the name of a _Routing Module_ contains the word "Routing" and
642
- aligns with the name of the module that declares the components navigated to".
643
-
644
- Create an `app-routing.module.ts` file as a sibling to `app.module.ts`. Give it the following contents extracted from the `AppModule` class:
651
+ By convention the name of a _Routing Module_ contains the word "Routing" and
652
+ aligns with the name of the module that declares the components navigated to.
645
653
646
- + makeExample('app/app-routing.module.ts' )
647
- :marked
648
- Noteworthy points, typical of _Routing Modules_:
649
- * Pull the routes into a variable. You might export it in future and it clarifies the _Routing Module_ pattern.
654
+ Create an `app-routing.module.ts` file as a sibling to `app.module.ts`. Give it the following contents extracted from the `AppModule` class:
650
655
651
- * Add `RouterModule.forRoot(routes)` to `imports`.
652
-
653
- * Add `RouterModule` to `exports` so that the components in the companion module have access to Router declarables
654
- such as `RouterLink` and `RouterOutlet`.
655
-
656
- * No `declarations`! Declarations are the responsibility of the companion module.
656
+ + makeExample('app/app-routing.module.ts' )
657
+ :marked
658
+ Noteworthy points, typical of _Routing Modules_:
659
+ * Pull the routes into a variable. You might export it in future and it clarifies the _Routing Module_ pattern.
657
660
658
- * Add module `providers` for guard services if you have them; there are none in this example .
661
+ * Add `RouterModule.forRoot(routes)` to `imports` .
659
662
660
- ### Update _AppModule_
663
+ * Add `RouterModule` to `exports` so that the components in the companion module have access to Router declarables
664
+ such as `RouterLink` and `RouterOutlet`.
661
665
662
- Now delete the routing configuration from `AppModule` and import the `AppRoutingModule`
663
- (_both_ with an ES `import` statement _and_ by adding it to the `NgModule.imports` list).
666
+ * No `declarations`! Declarations are the responsibility of the companion module.
667
+
668
+ * Add module `providers` for guard services if you have them; there are none in this example.
669
+
670
+ ### Update _AppModule_
671
+
672
+ Now delete the routing configuration from `AppModule` and import the `AppRoutingModule`
673
+ (_both_ with an ES `import` statement _and_ by adding it to the `NgModule.imports` list).
674
+
675
+ Here is the revised `AppModule`, compared to its pre-refactor state:
676
+ + makeTabs(
677
+ ` toh-5/ts/app/app.module.ts, toh-5/ts/app/app.module.3.ts` ,
678
+ null ,
679
+ ` app/app.module.ts (after), app/app.module.ts (before)` )
680
+ :marked
681
+ It's simpler and focused on indentifying the key pieces of the application.
664
682
665
- Here is the revised `AppModule`, compared to its pre-refactor state:
666
- + makeTabs(
667
- ` toh-5/ts/app/app.module.ts, toh-5/ts/app/app.module.3.ts` ,
668
- null ,
669
- ` app/app.module.ts (after), app/app.module.ts (before)` )
670
- :marked
671
- It's simpler and focused on indentifying the key pieces of the application.
672
683
.l-main-section
673
684
:marked
674
685
## Select a Hero in the *HeroesComponent*
@@ -738,7 +749,7 @@ figure.image-display
738
749
1. *Cut-and-paste* the template contents into a new <span ngio-ex>heroes.component.html</span> file.
739
750
1. *Cut-and-paste* the styles contents into a new <span ngio-ex>heroes.component.css</span> file.
740
751
1. *Set* the component metadata's `templateUrl` and `styleUrls` properties to refer to both files.
741
- 1 . *Set* the `moduleId` property to `module.id` so that `templateUrl` and `styleUrls` are relative to the component.
752
+ <li if-docs="ts"> . *Set* the `moduleId` property to `module.id` so that `templateUrl` and `styleUrls` are relative to the component.</li>
742
753
743
754
.l-sub-section
744
755
:marked
@@ -764,11 +775,12 @@ block heroes-component-cleanup
764
775
1. Implement `gotoDetail` by calling the `router.navigate` method
765
776
766
777
+ makeExcerpt('app/heroes.component.ts' , 'gotoDetail' )
778
+
767
779
:marked
768
780
Note that we're passing a two-element **link parameters !{_array}**
769
781
— a path and the route parameter — to
770
782
the `router.navigate` method just as we did in the `[routerLink]` binding
771
- back in the `DashboardComponent`
783
+ back in the `DashboardComponent`.
772
784
Here's the fully revised `HeroesComponent` class:
773
785
774
786
+ makeExcerpt('app/heroes.component.ts' , 'class' )
@@ -934,7 +946,7 @@ block file-tree-end
934
946
- We shared the `HeroService` among multiple components.
935
947
- We moved HTML and CSS out of the component file and into their own files.
936
948
- We added the `uppercase` pipe to format data.
937
- - We refactored routes into a `Routing Module` that we import.
949
+ <li if-docs="ts"> We refactored routes into a `Routing Module` that we import.</li>
938
950
939
951
### The Road Ahead
940
952
0 commit comments