Skip to content

Commit

Permalink
prevent undefined hero detail id
Browse files Browse the repository at this point in the history
  • Loading branch information
javiersvg committed Mar 8, 2020
1 parent 0034f70 commit 4b8e60a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/app/hero/hero-detail/hero-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ export class HeroDetailComponent implements OnInit {
}

getHero(): void {
const id = this.route.snapshot.paramMap.get('id');
this.heroService.get(id)
.subscribe(hero => this.hero = hero);
const id = this.route?.snapshot.paramMap.get('id');
if(id) {
this.heroService.get(id)
.subscribe(hero => this.hero = hero);
}
}

goBack(): void {
Expand Down

0 comments on commit 4b8e60a

Please sign in to comment.