X-Git-Url: https://juplo.de/gitweb/?p=examples%2Fangular-tour-of-heroes;a=blobdiff_plain;f=src%2Fapp%2Fheroes%2Fheroes.component.ts;h=94f426656a78890c89a2966a9d9d7687511858eb;hp=dd46908615ccee92a0a4dc01a6967484ef429804;hb=ef15a90ba71bcff7765f089af11e2ad22752a352;hpb=58e4e8a43a7f0ea82123c6149ff475b62c6dc372 diff --git a/src/app/heroes/heroes.component.ts b/src/app/heroes/heroes.component.ts index dd46908..94f4266 100644 --- a/src/app/heroes/heroes.component.ts +++ b/src/app/heroes/heroes.component.ts @@ -1,5 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { Hero } from '../hero'; +import { HeroService } from '../hero.service'; @Component({ selector: 'app-heroes', @@ -8,14 +9,21 @@ import { Hero } from '../hero'; }) 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(); + } }