import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
+import { HeroService } from '../hero.service';
@Component({
selector: 'app-heroes',
})
export class HeroesComponent implements OnInit {
- hero: Hero = {
- id: 1,
- name: 'Windstorm',
- };
+ heroes: Hero[];
- constructor() { }
+ selectedHero : Hero;
+
+ onSelect(hero : Hero): void {
+ this.selectedHero = hero;
+ }
+
+ constructor(private heroService : HeroService) { }
ngOnInit() {
+ this.getHeroes();
}
+ getHeroes() : void {
+ this.heroes = this.heroService.getHeroes();
+ }
}