| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  | // #docplaster
 | 
					
						
							|  |  |  | // #docregion
 | 
					
						
							| 
									
										
										
										
											2016-04-27 11:28:22 -07:00
										 |  |  | import { Component, OnInit } from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2016-06-19 00:20:38 -04:00
										 |  |  | import { Router } from '@angular/router'; | 
					
						
							| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import { Hero } from './hero'; | 
					
						
							|  |  |  | import { HeroService } from './hero.service'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-17 13:31:40 -07:00
										 |  |  | // #docregion renaming, metadata
 | 
					
						
							| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  | @Component({ | 
					
						
							| 
									
										
										
										
											2016-10-14 01:41:57 +02:00
										 |  |  |   // #enddocregion renaming
 | 
					
						
							| 
									
										
										
										
											2016-09-25 18:51:54 -07:00
										 |  |  |   moduleId: module.id, | 
					
						
							| 
									
										
										
										
											2016-10-14 01:41:57 +02:00
										 |  |  |   // #docregion renaming
 | 
					
						
							| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  |   selector: 'my-heroes', | 
					
						
							| 
									
										
										
										
											2016-08-17 13:31:40 -07:00
										 |  |  |   // #enddocregion renaming
 | 
					
						
							| 
									
										
										
										
											2016-09-25 18:51:54 -07:00
										 |  |  |   templateUrl: 'heroes.component.html', | 
					
						
							|  |  |  |   styleUrls: [ 'heroes.component.css' ] | 
					
						
							| 
									
										
										
										
											2016-08-17 13:31:40 -07:00
										 |  |  |   // #docregion renaming
 | 
					
						
							| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											2016-08-17 13:31:40 -07:00
										 |  |  | // #enddocregion metadata
 | 
					
						
							|  |  |  | // #docregion class
 | 
					
						
							| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  | export class HeroesComponent implements OnInit { | 
					
						
							| 
									
										
										
										
											2016-08-17 13:31:40 -07:00
										 |  |  |   // #enddocregion renaming
 | 
					
						
							| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  |   heroes: Hero[]; | 
					
						
							|  |  |  |   selectedHero: Hero; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   constructor( | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |     private router: Router, | 
					
						
							|  |  |  |     private heroService: HeroService) { } | 
					
						
							| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-27 15:00:59 +02:00
										 |  |  |   getHeroes(): void { | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |     this.heroService.getHeroes().then(heroes => this.heroes = heroes); | 
					
						
							| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-27 15:00:59 +02:00
										 |  |  |   ngOnInit(): void { | 
					
						
							| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  |     this.getHeroes(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-27 15:00:59 +02:00
										 |  |  |   onSelect(hero: Hero): void { | 
					
						
							|  |  |  |     this.selectedHero = hero; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-03 10:25:01 -07:00
										 |  |  |   // #docregion gotoDetail
 | 
					
						
							| 
									
										
										
										
											2016-07-27 15:00:59 +02:00
										 |  |  |   gotoDetail(): void { | 
					
						
							| 
									
										
										
										
											2016-06-19 00:20:38 -04:00
										 |  |  |     this.router.navigate(['/detail', this.selectedHero.id]); | 
					
						
							| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-11-03 10:25:01 -07:00
										 |  |  |   // #enddocregion gotoDetail
 | 
					
						
							| 
									
										
										
										
											2016-08-17 13:31:40 -07:00
										 |  |  |   // #docregion renaming
 | 
					
						
							| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  | } |