From fd92a662c471619278e561f25a4beb7ef78d0690 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 10 May 2020 22:43:49 +0200 Subject: [PATCH] HeroDetailComponent issues a message after successfull retrival of a hero --- src/app/hero-detail/hero-detail.component.ts | 7 ++++++- src/app/hero.service.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/hero-detail/hero-detail.component.ts b/src/app/hero-detail/hero-detail.component.ts index 4bbfe2e..76e7912 100644 --- a/src/app/hero-detail/hero-detail.component.ts +++ b/src/app/hero-detail/hero-detail.component.ts @@ -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; + }); }); } diff --git a/src/app/hero.service.ts b/src/app/hero.service.ts index 1db6072..649b856 100644 --- a/src/app/hero.service.ts +++ b/src/app/hero.service.ts @@ -18,7 +18,7 @@ export class HeroService { } getHero(id: number): Observable { - this.messageService.add(`HeroService: fetched hero id=${id}`); + this.messageService.add(`HeroService: requested hero id=${id}`); const found: Hero | undefined = HEROES.find(hero => hero.id === id); if (found === undefined) { return EMPTY; -- 2.20.1