HeroDetailComponent issues a message after successfull retrival of a hero
[examples/angular-tour-of-heroes] / src / app / hero-detail / hero-detail.component.ts
index 4bbfe2e..76e7912 100644 (file)
@@ -4,6 +4,7 @@ import { Location } from '@angular/common';
 
 import { HeroService } from '../hero.service';
 import { Hero } from '../hero';
+import { MessageService } from '../message.service';
 
 @Component({
   selector: 'app-hero-detail',
@@ -17,6 +18,7 @@ export class HeroDetailComponent implements OnInit {
   constructor(
     private route: ActivatedRoute,
     private heroService: HeroService,
+    private messageService: MessageService,
     private location: Location
   ) { }
 
@@ -28,7 +30,10 @@ export class HeroDetailComponent implements OnInit {
     this.route.params.subscribe(params => {
       const id: number = +params.id;
       this.hero = undefined;
-      this.heroService.getHero(id).subscribe(hero => this.hero = hero);
+      this.heroService.getHero(id).subscribe(hero => {
+        this.messageService.add('HeroDetailComponent: retrived hero ' + JSON.stringify(hero));
+        this.hero = hero;
+      });
     });
   }