From cfdc1d228b90a65ef26d432b62504ee1c0ab0d04 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 10 May 2020 22:42:52 +0200 Subject: [PATCH] Hero in HeroDetailComponent can be undefined: resetting prior to fetching --- src/app/hero-detail/hero-detail.component.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/hero-detail/hero-detail.component.ts b/src/app/hero-detail/hero-detail.component.ts index d4c7289..4bbfe2e 100644 --- a/src/app/hero-detail/hero-detail.component.ts +++ b/src/app/hero-detail/hero-detail.component.ts @@ -12,7 +12,7 @@ import { Hero } from '../hero'; }) export class HeroDetailComponent implements OnInit { - hero: Hero; + hero: Hero | undefined; constructor( private route: ActivatedRoute, @@ -27,6 +27,7 @@ export class HeroDetailComponent implements OnInit { getHero(): void { this.route.params.subscribe(params => { const id: number = +params.id; + this.hero = undefined; this.heroService.getHero(id).subscribe(hero => this.hero = hero); }); } -- 2.20.1