Fixed test-case for HeroDetailComponent by making it easier testable
[examples/angular-tour-of-heroes] / src / app / hero-detail / hero-detail.component.ts
index c252bcf..aef0da5 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 {