| 
									
										
										
										
											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_service.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-17 13:31:40 -07:00
										 |  |  | // #docregion metadata, renaming
 | 
					
						
							| 
									
										
										
										
											2016-03-16 14:39:06 -04:00
										 |  |  | @Component( | 
					
						
							|  |  |  |     selector: 'my-heroes', | 
					
						
							| 
									
										
										
										
											2016-08-17 13:31:40 -07:00
										 |  |  |     // #enddocregion renaming
 | 
					
						
							| 
									
										
										
										
											2016-03-16 14:39:06 -04:00
										 |  |  |     templateUrl: 'heroes_component.html', | 
					
						
							| 
									
										
										
										
											2016-08-17 13:31:40 -07:00
										 |  |  |     styleUrls: const ['heroes_component.css'] | 
					
						
							|  |  |  | // #docregion renaming
 | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | // #enddocregion metadata
 | 
					
						
							|  |  |  | // #docregion class
 | 
					
						
							| 
									
										
										
										
											2016-03-16 14:39:06 -04:00
										 |  |  | class HeroesComponent implements OnInit { | 
					
						
							| 
									
										
										
										
											2016-08-17 13:31:40 -07:00
										 |  |  |   // #enddocregion renaming
 | 
					
						
							| 
									
										
										
										
											2016-03-16 14:39:06 -04:00
										 |  |  |   final Router _router; | 
					
						
							|  |  |  |   final HeroService _heroService; | 
					
						
							|  |  |  |   List<Hero> heroes; | 
					
						
							|  |  |  |   Hero selectedHero; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-17 13:31:40 -07:00
										 |  |  |   // #docregion renaming
 | 
					
						
							| 
									
										
										
										
											2016-03-16 14:39:06 -04:00
										 |  |  |   HeroesComponent(this._heroService, this._router); | 
					
						
							| 
									
										
										
										
											2016-08-17 13:31:40 -07:00
										 |  |  |   // #enddocregion renaming
 | 
					
						
							| 
									
										
										
										
											2016-03-16 14:39:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-28 13:15:29 -07:00
										 |  |  |   void onSelect(Hero hero) { | 
					
						
							|  |  |  |     selectedHero = hero; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-03-16 14:39:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-28 13:15:29 -07:00
										 |  |  |   Future<Null> gotoDetail() => _router.navigate([ | 
					
						
							|  |  |  |         'HeroDetail', | 
					
						
							|  |  |  |         {'id': selectedHero.id.toString()} | 
					
						
							|  |  |  |       ]); | 
					
						
							| 
									
										
										
										
											2016-08-17 13:31:40 -07:00
										 |  |  |   // #docregion renaming
 | 
					
						
							| 
									
										
										
										
											2016-03-16 14:39:06 -04:00
										 |  |  | } |