]> juplo.de Git - examples/angular-tour-of-heroes/commitdiff
Fixed test-case for HeroDetailComponent by making it easier testable
authorKai Moritz <kai@juplo.de>
Mon, 11 May 2020 15:50:56 +0000 (17:50 +0200)
committerKai Moritz <kai@juplo.de>
Mon, 11 May 2020 16:23:16 +0000 (18:23 +0200)
src/app/hero-detail/hero-detail.component.ts

index c252bcffe4905eb339cd4ecbd01d71c7690a29f6..aef0da51f688957494410246dd1a1e77bd56e3a8 100644 (file)
@@ -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 {