angular-cn/public/docs/_examples/toh-5/dart/lib/heroes_component.dart
Patrice Chalin c7717b4850 docs(toh): fix code-example format and Dart code excerpt (#2907)
* ensure HeroesComponent renaming doesn't show router

* use code-example format consistent with the rest of the docs
2016-12-01 08:15:04 -08:00

56 lines
1.2 KiB
Dart

// #docplaster
// #docregion
import 'dart:async';
import 'package:angular2/core.dart';
import 'package:angular2/router.dart';
import 'hero.dart';
import 'hero_service.dart';
// #docregion metadata, renaming
@Component(
selector: 'my-heroes',
// #enddocregion renaming
templateUrl: 'heroes_component.html',
styleUrls: const ['heroes_component.css']
// #docregion renaming
)
// #enddocregion metadata
// #docregion class
class HeroesComponent implements OnInit {
// #enddocregion renaming
final Router _router;
final HeroService _heroService;
List<Hero> heroes;
Hero selectedHero;
// #docregion renaming
HeroesComponent(this._heroService,
// #enddocregion renaming
this._router
// #docregion renaming
);
// #enddocregion renaming
Future<Null> getHeroes() async {
heroes = await _heroService.getHeroes();
}
void ngOnInit() {
getHeroes();
}
void onSelect(Hero hero) {
selectedHero = hero;
}
// #docregion gotoDetail
Future<Null> gotoDetail() => _router.navigate([
'HeroDetail',
{'id': selectedHero.id.toString()}
]);
// #enddocregion gotoDetail
// #docregion renaming
}