33 lines
859 B
TypeScript
33 lines
859 B
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { Router } from '@angular/router-deprecated';
|
|
import { HeroService } from './hero.service';
|
|
import { HeroDetailComponent } from './hero-detail.component';
|
|
import { Hero } from './hero';
|
|
|
|
@Component({
|
|
selector: 'my-heroes',
|
|
templateUrl: 'app/heroes.component.html',
|
|
styleUrls: ['app/heroes.component.css'],
|
|
directives: [HeroDetailComponent]
|
|
})
|
|
export class HeroesComponent implements OnInit {
|
|
heroes: Hero[];
|
|
selectedHero: Hero;
|
|
|
|
constructor(private heroService: HeroService, private router: Router) { }
|
|
|
|
getHeroes() {
|
|
this.heroService.getHeroes().then(heroes => this.heroes = heroes);
|
|
}
|
|
|
|
gotoDetail() {
|
|
this.router.navigate(['HeroDetail', { id: this.selectedHero.id }]);
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.getHeroes();
|
|
}
|
|
|
|
onSelect(hero: Hero) { this.selectedHero = hero; }
|
|
}
|