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

Commit c24dd07

Browse files
chalinkwalrath
authored andcommitted
docs(toh-5/dart): use routerLink in dashboard (#2744)
* docs(toh-5/dart): use routerLink in dashboard * minor edits to TS jade * remove dart/toh-pt5 from bad-code-excerpt-skip-patterns
1 parent 2808878 commit c24dd07

File tree

10 files changed

+216
-152
lines changed

10 files changed

+216
-152
lines changed

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,37 @@
44
import 'dart:async';
55

66
import 'package:angular2/core.dart';
7+
// #docregion import-router
8+
import 'package:angular2/router.dart';
9+
// #enddocregion import-router
710

811
import 'hero.dart';
912
import 'hero_service.dart';
1013
// #enddocregion imports
1114

15+
// #docregion metadata
1216
@Component(
1317
selector: 'my-dashboard',
1418
// #docregion templateUrl
1519
templateUrl: 'dashboard_component.html',
1620
// #enddocregion templateUrl
1721
// #docregion css
18-
styleUrls: const ['dashboard_component.css']
22+
styleUrls: const ['dashboard_component.css'],
1923
// #enddocregion css
24+
directives: const [ROUTER_DIRECTIVES],
2025
)
21-
// #docregion component
26+
// #enddocregion metadata
27+
// #docregion class, component
2228
class DashboardComponent implements OnInit {
2329
List<Hero> heroes;
2430

2531
// #docregion ctor
2632
final HeroService _heroService;
2733

2834
DashboardComponent(this._heroService);
29-
3035
// #enddocregion ctor
3136

3237
Future<Null> ngOnInit() async {
3338
heroes = (await _heroService.getHeroes()).skip(1).take(4).toList();
3439
}
3540
}
36-
// #enddocregion component

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

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

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// #docregion , v2
33
// #docregion added-imports
44
import 'dart:async';
5-
import 'dart:html' show window;
65

76
// #enddocregion added-imports
87
import 'package:angular2/core.dart';
98
// #docregion added-imports
109
import 'package:angular2/router.dart';
10+
import 'package:angular2/platform/common.dart';
1111

1212
// #enddocregion added-imports
1313
import 'hero.dart';
@@ -17,9 +17,9 @@ import 'hero_service.dart';
1717

1818
@Component(
1919
selector: 'my-hero-detail',
20-
// #docregion templateUrl
20+
// #docregion metadata, templateUrl
2121
templateUrl: 'hero_detail_component.html',
22-
// #enddocregion templateUrl, v2
22+
// #enddocregion metadata, templateUrl, v2
2323
styleUrls: const ['hero_detail_component.css']
2424
// #docregion v2
2525
)
@@ -30,8 +30,9 @@ class HeroDetailComponent implements OnInit {
3030
// #docregion ctor
3131
final HeroService _heroService;
3232
final RouteParams _routeParams;
33+
final Location _location;
3334

34-
HeroDetailComponent(this._heroService, this._routeParams);
35+
HeroDetailComponent(this._heroService, this._routeParams, this._location);
3536
// #enddocregion ctor
3637

3738
// #docregion ngOnInit
@@ -44,7 +45,7 @@ class HeroDetailComponent implements OnInit {
4445

4546
// #docregion goBack
4647
void goBack() {
47-
window.history.back();
48+
_location.back();
4849
}
4950
// #enddocregion goBack
5051
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ class HeroesComponent implements OnInit {
4141
selectedHero = hero;
4242
}
4343

44+
// #docregion gotoDetail
4445
Future<Null> gotoDetail() => _router.navigate([
4546
'HeroDetail',
4647
{'id': selectedHero.id.toString()}
4748
]);
49+
// #enddocregion gotoDetail
4850
// #docregion renaming
4951
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ export class DashboardComponent implements OnInit {
3333
.then(heroes => this.heroes = heroes.slice(1, 5));
3434
}
3535
}
36-
// #enddocregion class

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ block redirect-vs-use-as-default
9696
router will display the dashboard when the browser URL doesn't match an existing route.
9797

9898
block templateUrl-path-resolution
99-
:marked
100-
The value of `templateUrl` can be an [asset][] in this package or another
101-
package. To use an asset in another package, use a full package reference,
102-
such as `'package:some_other_package/dashboard_component.html'`.
99+
.l-sub-section
100+
:marked
101+
The value of `templateUrl` can be an [asset][] in this package or another
102+
package. To use an asset in another package, use a full package reference,
103+
such as `'package:some_other_package/dashboard_component.html'`.
103104

104-
[asset]: https://www.dartlang.org/tools/pub/glossary#asset
105+
[asset]: https://www.dartlang.org/tools/pub/glossary#asset
105106

106107
block route-params
107108
:marked

0 commit comments

Comments
 (0)