forked from angular/angular.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheroes.component.ts
More file actions
33 lines (27 loc) · 870 Bytes
/
heroes.component.ts
File metadata and controls
33 lines (27 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// #docregion imports
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router-deprecated';
import { HeroService, Hero } from './shared';
import { HeroDetailComponent } from './hero-detail'
@Component({
// #enddocregion
selector: 'my-heroes',
templateUrl: 'app/heroes/heroes.component.html',
styleUrls: ['app/heroes/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; }
}