2016-03-16 14:39:06 -04:00
|
|
|
// #docplaster
|
|
|
|
// #docregion
|
|
|
|
import 'dart:async';
|
|
|
|
|
2016-03-25 16:03:53 -07:00
|
|
|
import 'package:angular2/core.dart';
|
2016-03-16 14:39:06 -04:00
|
|
|
import 'package:angular2/router.dart';
|
|
|
|
|
|
|
|
import 'hero.dart';
|
|
|
|
import 'hero_detail_component.dart';
|
|
|
|
import 'hero_service.dart';
|
|
|
|
|
2016-06-15 07:46:26 -07:00
|
|
|
// #docregion metadata, heroes-component-renaming
|
2016-03-16 14:39:06 -04:00
|
|
|
@Component(
|
|
|
|
selector: 'my-heroes',
|
2016-06-15 07:46:26 -07:00
|
|
|
// #enddocregion heroes-component-renaming
|
2016-03-16 14:39:06 -04:00
|
|
|
templateUrl: 'heroes_component.html',
|
|
|
|
styleUrls: const ['heroes_component.css'],
|
|
|
|
directives: const [HeroDetailComponent]
|
2016-06-15 07:46:26 -07:00
|
|
|
// #docregion heroes-component-renaming
|
2016-03-16 14:39:06 -04:00
|
|
|
)
|
2016-06-15 07:46:26 -07:00
|
|
|
// #enddocregion heroes-component-renaming, metadata
|
|
|
|
// #docregion class, heroes-component-renaming
|
2016-03-16 14:39:06 -04:00
|
|
|
class HeroesComponent implements OnInit {
|
2016-06-15 07:46:26 -07:00
|
|
|
// #enddocregion heroes-component-renaming
|
2016-03-16 14:39:06 -04:00
|
|
|
final Router _router;
|
|
|
|
final HeroService _heroService;
|
|
|
|
List<Hero> heroes;
|
|
|
|
Hero selectedHero;
|
|
|
|
|
|
|
|
HeroesComponent(this._heroService, this._router);
|
|
|
|
|
2016-06-15 07:46:26 -07:00
|
|
|
Future<Null> getHeroes() async {
|
2016-03-16 14:39:06 -04:00
|
|
|
heroes = await _heroService.getHeroes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ngOnInit() {
|
|
|
|
getHeroes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void onSelect(Hero hero) { selectedHero = hero; }
|
|
|
|
|
2016-06-15 07:46:26 -07:00
|
|
|
Future<Null> gotoDetail() =>
|
2016-03-16 14:39:06 -04:00
|
|
|
_router.navigate(['HeroDetail', {'id': selectedHero.id.toString()}]);
|
2016-06-15 07:46:26 -07:00
|
|
|
// #docregion heroes-component-renaming
|
2016-03-16 14:39:06 -04:00
|
|
|
}
|