You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
637 B
32 lines
637 B
import { Component, OnInit } from '@angular/core';
|
|
import { Router } from '@angular/router';
|
|
|
|
import { Hero } from './hero';
|
|
|
|
@Component({
|
|
selector: 'my-heroes',
|
|
styleUrls: [ './heroes.component.css' ]
|
|
})
|
|
export class HeroesComponent implements OnInit {
|
|
heroes: Hero[];
|
|
selectedHero: Hero;
|
|
|
|
constructor(
|
|
private heroService: HeroService) { }
|
|
|
|
getHeroes(): void {
|
|
this.heroService.getHeroes().then(heroes => this.heroes = heroes);
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
}
|
|
|
|
onSelect(hero: Hero): void {
|
|
this.selectedHero = hero;
|
|
}
|
|
|
|
gotoDetail(): void {
|
|
this.router.navigate(['/detail', this.selectedHero.id]);
|
|
}
|
|
}
|