X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Fhero-detail%2Fhero-detail.component.ts;h=d4c72891e301a09cc54fd9979ddf5108cd8b0e92;hb=69d83392a0c41cd9fa012b69efdb5f6f2a046886;hp=c252bcffe4905eb339cd4ecbd01d71c7690a29f6;hpb=f18faff7c576b595dd8765f36805aa8176122db7;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 c252bcf..d4c7289 100644 --- a/src/app/hero-detail/hero-detail.component.ts +++ b/src/app/hero-detail/hero-detail.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Input } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { Location } from '@angular/common'; @@ -12,7 +12,7 @@ import { Hero } from '../hero'; }) export class HeroDetailComponent implements OnInit { - @Input() hero : Hero; + hero: Hero; constructor( private route: ActivatedRoute, @@ -25,8 +25,10 @@ export class HeroDetailComponent implements OnInit { } getHero(): void { - const id = +this.route.snapshot.paramMap.get('id'); - this.heroService.getHero(id).subscribe(hero => this.hero = hero); + this.route.params.subscribe(params => { + const id: number = +params.id; + this.heroService.getHero(id).subscribe(hero => this.hero = hero); + }); } goBack(): void {