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