From: Kai Moritz Date: Sun, 10 May 2020 20:43:49 +0000 (+0200) Subject: HeroDetailComponent issues a message after successfull retrival of a hero X-Git-Url: https://juplo.de/gitweb/?p=examples%2Fangular-tour-of-heroes;a=commitdiff_plain;h=fd92a662c471619278e561f25a4beb7ef78d0690 HeroDetailComponent issues a message after successfull retrival of a hero --- 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;