2015-12-23 09:42:57 -08:00
|
|
|
// #docplaster
|
|
|
|
// #docregion
|
2016-04-27 11:28:22 -07:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { Router } from '@angular/router-deprecated';
|
2015-12-23 09:42:57 -08:00
|
|
|
|
|
|
|
import { Hero } from './hero';
|
|
|
|
import { HeroService } from './hero.service';
|
|
|
|
|
2016-06-10 09:37:33 -07:00
|
|
|
// #docregion heroes-component-renaming, metadata
|
2015-12-23 09:42:57 -08:00
|
|
|
@Component({
|
|
|
|
selector: 'my-heroes',
|
2016-06-10 09:37:33 -07:00
|
|
|
// #enddocregion heroes-component-renaming
|
2015-12-23 09:42:57 -08:00
|
|
|
templateUrl: 'app/heroes.component.html',
|
2016-05-19 00:57:35 -07:00
|
|
|
styleUrls: ['app/heroes.component.css']
|
2016-06-10 09:37:33 -07:00
|
|
|
// #docregion heroes-component-renaming
|
2015-12-23 09:42:57 -08:00
|
|
|
})
|
2016-06-10 09:37:33 -07:00
|
|
|
// #enddocregion heroes-component-renaming, metadata
|
|
|
|
// #docregion class, heroes-component-renaming
|
2015-12-23 09:42:57 -08:00
|
|
|
export class HeroesComponent implements OnInit {
|
2016-06-10 09:37:33 -07:00
|
|
|
// #enddocregion heroes-component-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
|
|
|
|
|
|
|
getHeroes() {
|
2016-05-03 14:06:32 +02:00
|
|
|
this.heroService.getHeroes().then(heroes => this.heroes = heroes);
|
2015-12-23 09:42:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.getHeroes();
|
|
|
|
}
|
|
|
|
|
|
|
|
onSelect(hero: Hero) { this.selectedHero = hero; }
|
|
|
|
|
|
|
|
gotoDetail() {
|
2016-05-03 14:06:32 +02:00
|
|
|
this.router.navigate(['HeroDetail', { id: this.selectedHero.id }]);
|
2015-12-23 09:42:57 -08:00
|
|
|
}
|
2016-06-10 09:37:33 -07:00
|
|
|
// #docregion heroes-component-renaming
|
2015-12-23 09:42:57 -08:00
|
|
|
}
|