- 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.hero = undefined;
+ this.heroService.getHero(id).subscribe(hero => {
+ this.messageService.add('HeroDetailComponent: retrived hero ' + JSON.stringify(hero));
+ this.hero = hero;
+ });
+ });
+ }
+
+ save(): void {
+ this.heroService.updateHero(this.hero)
+ .subscribe(() => this.goBack());