From f6721b579dc10a1412804c1ab78c7865d6d91dd0 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 11 May 2020 17:50:56 +0200 Subject: [PATCH] Fixed test-case for HeroDetailComponent by making it easier testable --- src/app/hero-detail/hero-detail.component.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/hero-detail/hero-detail.component.ts b/src/app/hero-detail/hero-detail.component.ts index c252bcf..aef0da5 100644 --- a/src/app/hero-detail/hero-detail.component.ts +++ b/src/app/hero-detail/hero-detail.component.ts @@ -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 { -- 2.20.1