X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Fhero-detail%2Fhero-detail.component.ts;h=aef0da51f688957494410246dd1a1e77bd56e3a8;hb=f6721b579dc10a1412804c1ab78c7865d6d91dd0;hp=caa9c091e162601ab48c8c6d150e1aa7c2ac6aa4;hpb=aa0556604bc625981bfd2f787f7b1ef2dadb9938;p=examples%2Fangular-tour-of-heroes diff --git a/src/app/hero-detail/hero-detail.component.ts b/src/app/hero-detail/hero-detail.component.ts index caa9c09..aef0da5 100644 --- a/src/app/hero-detail/hero-detail.component.ts +++ b/src/app/hero-detail/hero-detail.component.ts @@ -1,4 +1,8 @@ import { Component, OnInit, Input } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { Location } from '@angular/common'; + +import { HeroService } from '../hero.service'; import { Hero } from '../hero'; @Component({ @@ -10,9 +14,24 @@ export class HeroDetailComponent implements OnInit { @Input() hero : Hero; - constructor() { } + constructor( + private route: ActivatedRoute, + private heroService: HeroService, + private location: Location + ) { } ngOnInit() { + this.getHero(); + } + + getHero(): void { + this.route.params.subscribe(params => { + const id: number = +params.id; + this.heroService.getHero(id).subscribe(hero => this.hero = hero); + }); } + goBack(): void { + this.location.back(); + } }