import { HeroService } from '../hero.service';
import { Hero } from '../hero';
+import { MessageService } from '../message.service';
@Component({
selector: 'app-hero-detail',
constructor(
private route: ActivatedRoute,
private heroService: HeroService,
+ private messageService: MessageService,
private location: Location
) { }
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;
+ });
});
}
}
getHero(id: number): Observable<Hero> {
- 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;