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

Commit fa99a8b

Browse files
authored
docs(toh-5): dashboard uses [routerLink] bindings #998 (#2718)
* docs(toh-5): dashboard uses [routerLink] bindings #998 closes #998 * chore: temp add toh-5 to bad-code-excerpt-skip-patterns.txt
1 parent ae35f0e commit fa99a8b

21 files changed

+187
-266
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- #docregion -->
2+
<h3>Top Heroes</h3>
3+
<div class="grid grid-pad">
4+
<div *ngFor="let hero of heroes" class="col-1-4">
5+
<div class="module hero">
6+
<h4>{{hero.name}}</h4>
7+
</div>
8+
</div>
9+
</div>

public/docs/_examples/toh-5/dart/lib/dashboard_component.css

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
/* #docregion */
22
[class*='col-'] {
33
float: left;
4+
text-decoration: none;
5+
padding-right: 20px;
6+
padding-bottom: 20px;
7+
}
8+
[class*='col-']:last-of-type {
9+
padding-right: 0;
410
}
511
*, *:after, *:before {
612
-webkit-box-sizing: border-box;
@@ -10,12 +16,8 @@
1016
h3 {
1117
text-align: center; margin-bottom: 0;
1218
}
13-
[class*='col-'] {
14-
padding-right: 20px;
15-
padding-bottom: 20px;
16-
}
17-
[class*='col-']:last-of-type {
18-
padding-right: 0;
19+
h4 {
20+
position: relative;
1921
}
2022
.grid {
2123
margin: 0;
@@ -32,9 +34,6 @@ h3 {
3234
background-color: #607D8B;
3335
border-radius: 2px;
3436
}
35-
h4 {
36-
position: relative;
37-
}
3837
.module:hover {
3938
background-color: #EEE;
4039
cursor: pointer;
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// #docplaster
22
// #docregion
3+
// #docregion imports
34
import 'dart:async';
45

56
import 'package:angular2/core.dart';
6-
// #docregion import-router
7-
import 'package:angular2/router.dart';
8-
// #enddocregion import-router
97

108
import 'hero.dart';
119
import 'hero_service.dart';
10+
// #enddocregion imports
1211

1312
@Component(
1413
selector: 'my-dashboard',
@@ -24,24 +23,14 @@ class DashboardComponent implements OnInit {
2423
List<Hero> heroes;
2524

2625
// #docregion ctor
27-
final Router _router;
2826
final HeroService _heroService;
2927

30-
DashboardComponent(this._heroService, this._router);
28+
DashboardComponent(this._heroService);
3129

3230
// #enddocregion ctor
3331

3432
Future<Null> ngOnInit() async {
3533
heroes = (await _heroService.getHeroes()).skip(1).take(4).toList();
3634
}
37-
38-
// #docregion gotoDetail
39-
void gotoDetail(Hero hero) {
40-
var link = [
41-
'HeroDetail',
42-
{'id': hero.id.toString()}
43-
];
44-
_router.navigate(link);
45-
}
46-
// #enddocregion gotoDetail
4735
}
36+
// #enddocregion component

public/docs/_examples/toh-5/dart/lib/dashboard_component.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<h3>Top Heroes</h3>
33
<div class="grid grid-pad">
44
<!-- #docregion click -->
5-
<div *ngFor="let hero of heroes" (click)="gotoDetail(hero)" class="col-1-4" >
6-
<!-- #enddocregion click -->
5+
<a *ngFor="let hero of heroes" [routerLink]="['/detail', hero.id]" class="col-1-4">
6+
<!-- #enddocregion click -->
77
<div class="module hero">
88
<h4>{{hero.name}}</h4>
99
</div>
10-
</div>
10+
</a>
1111
</div>

public/docs/_examples/toh-5/dart/lib/dashboard_component_2.dart

-26
This file was deleted.

public/docs/_examples/toh-5/e2e-spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict'; // necessary for es6 output in node
1+
'use strict'; // necessary for es6 output in node
22

33
import { browser, element, by, ElementFinder } from 'protractor';
44
import { promise } from 'selenium-webdriver';
@@ -42,16 +42,16 @@ describe('Tutorial part 5', () => {
4242
beforeAll(() => browser.get(''));
4343

4444
function getPageElts() {
45-
let hrefElts = element.all(by.css('my-app a'));
45+
let navElts = element.all(by.css('my-app nav a'));
4646

4747
return {
48-
hrefs: hrefElts,
48+
navElts: navElts,
4949

50-
myDashboardHref: hrefElts.get(0),
50+
myDashboardHref: navElts.get(0),
5151
myDashboard: element(by.css('my-app my-dashboard')),
5252
topHeroes: element.all(by.css('my-app my-dashboard > div h4')),
5353

54-
myHeroesHref: hrefElts.get(1),
54+
myHeroesHref: navElts.get(1),
5555
myHeroes: element(by.css('my-app my-heroes')),
5656
allHeroes: element.all(by.css('my-app my-heroes li')),
5757
selectedHero: element(by.css('my-app li.selected')),
@@ -73,7 +73,7 @@ describe('Tutorial part 5', () => {
7373

7474
const expectedViewNames = ['Dashboard', 'Heroes'];
7575
it(`has views ${expectedViewNames}`, () => {
76-
let viewNames = getPageElts().hrefs.map((el: ElementFinder) => el.getText());
76+
let viewNames = getPageElts().navElts.map((el: ElementFinder) => el.getText());
7777
expect(viewNames).toEqual(expectedViewNames);
7878
});
7979

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- #docregion -->
2+
<h3>Top Heroes</h3>
3+
<div class="grid grid-pad">
4+
<div *ngFor="let hero of heroes" class="col-1-4">
5+
<div class="module hero">
6+
<h4>{{hero.name}}</h4>
7+
</div>
8+
</div>
9+
</div>

public/docs/_examples/toh-5/ts/app/dashboard.component.2.ts

-27
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
/* #docregion */
22
[class*='col-'] {
33
float: left;
4+
padding-right: 20px;
5+
padding-bottom: 20px;
6+
}
7+
[class*='col-']:last-of-type {
8+
padding-right: 0;
9+
}
10+
a {
11+
text-decoration: none;
412
}
513
*, *:after, *:before {
6-
-webkit-box-sizing: border-box;
7-
-moz-box-sizing: border-box;
8-
box-sizing: border-box;
14+
-webkit-box-sizing: border-box;
15+
-moz-box-sizing: border-box;
16+
box-sizing: border-box;
917
}
1018
h3 {
1119
text-align: center; margin-bottom: 0;
1220
}
13-
[class*='col-'] {
14-
padding-right: 20px;
15-
padding-bottom: 20px;
16-
}
17-
[class*='col-']:last-of-type {
18-
padding-right: 0;
21+
h4 {
22+
position: relative;
1923
}
2024
.grid {
2125
margin: 0;
@@ -24,16 +28,13 @@ h3 {
2428
width: 25%;
2529
}
2630
.module {
27-
padding: 20px;
28-
text-align: center;
29-
color: #eee;
30-
max-height: 120px;
31-
min-width: 120px;
32-
background-color: #607D8B;
33-
border-radius: 2px;
34-
}
35-
h4 {
36-
position: relative;
31+
padding: 20px;
32+
text-align: center;
33+
color: #eee;
34+
max-height: 120px;
35+
min-width: 120px;
36+
background-color: #607D8B;
37+
border-radius: 2px;
3738
}
3839
.module:hover {
3940
background-color: #EEE;
@@ -47,15 +48,15 @@ h4 {
4748
padding-right: 20px;
4849
}
4950
@media (max-width: 600px) {
50-
.module {
51-
font-size: 10px;
52-
max-height: 75px; }
51+
.module {
52+
font-size: 10px;
53+
max-height: 75px; }
5354
}
5455
@media (max-width: 1024px) {
55-
.grid {
56-
margin: 0;
57-
}
58-
.module {
59-
min-width: 60px;
60-
}
56+
.grid {
57+
margin: 0;
58+
}
59+
.module {
60+
min-width: 60px;
61+
}
6162
}

public/docs/_examples/toh-5/ts/app/dashboard.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<h3>Top Heroes</h3>
33
<div class="grid grid-pad">
44
<!-- #docregion click -->
5-
<div *ngFor="let hero of heroes" (click)="gotoDetail(hero)" class="col-1-4">
5+
<a *ngFor="let hero of heroes" [routerLink]="['/detail', hero.id]" class="col-1-4">
66
<!-- #enddocregion click -->
77
<div class="module hero">
88
<h4>{{hero.name}}</h4>
99
</div>
10-
</div>
10+
</a>
1111
</div>
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// #docplaster
22
// #docregion
3+
// #docregion imports
34
import { Component, OnInit } from '@angular/core';
4-
// #docregion import-router
5-
import { Router } from '@angular/router';
6-
// #enddocregion import-router
75

86
import { Hero } from './hero';
97
import { HeroService } from './hero.service';
10-
// #docregion metadata
8+
// #enddocregion imports
9+
10+
// #docregion metadata
1111
@Component({
1212
moduleId: module.id,
1313
selector: 'my-dashboard',
@@ -19,27 +19,18 @@ import { HeroService } from './hero.service';
1919
// #docregion metadata
2020
})
2121
// #enddocregion metadata
22-
// #docregion component
22+
// #docregion class
2323
export class DashboardComponent implements OnInit {
2424

2525
heroes: Hero[] = [];
2626

2727
// #docregion ctor
28-
constructor(
29-
private router: Router,
30-
private heroService: HeroService) {
31-
}
28+
constructor(private heroService: HeroService) { }
3229
// #enddocregion ctor
3330

3431
ngOnInit(): void {
3532
this.heroService.getHeroes()
3633
.then(heroes => this.heroes = heroes.slice(1, 5));
3734
}
38-
39-
// #docregion gotoDetail
40-
gotoDetail(hero: Hero): void {
41-
let link = ['/detail', hero.id];
42-
this.router.navigate(link);
43-
}
44-
// #enddocregion gotoDetail
4535
}
36+
// #enddocregion class

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

+2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ export class HeroesComponent implements OnInit {
4040
this.selectedHero = hero;
4141
}
4242

43+
// #docregion gotoDetail
4344
gotoDetail(): void {
4445
this.router.navigate(['/detail', this.selectedHero.id]);
4546
}
47+
// #enddocregion gotoDetail
4648
// #docregion renaming
4749
}

0 commit comments

Comments
 (0)