// #docregion import 'dart:async'; import 'package:angular2/core.dart'; import 'package:angular2/router.dart'; import 'hero.dart'; import 'hero_detail_component.dart'; import 'hero_service.dart'; @Component( selector: 'my-heroes', templateUrl: 'heroes_component.html', styleUrls: const ['heroes_component.css'], directives: const [HeroDetailComponent]) class HeroesComponent implements OnInit { List heroes; Hero selectedHero; final HeroService _heroService; final Router _router; HeroesComponent(this._heroService, this._router); Future getHeroes() async { heroes = await _heroService.getHeroes(); } // #docregion add Future add(String name) async { name = name.trim(); if (name.isEmpty) return; heroes.add(await _heroService.create(name)); selectedHero = null; } // #enddocregion add // #docregion delete Future delete(Hero hero) async { await _heroService.delete(hero.id); heroes.remove(hero); if (selectedHero == hero) selectedHero = null; } // #enddocregion delete void ngOnInit() { getHeroes(); } void onSelect(Hero hero) { selectedHero = hero; } Future gotoDetail() => _router.navigate([ 'HeroDetail', {'id': selectedHero.id.toString()} ]); }