X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Fhero-detail%2Fhero-detail.component.ts;h=caeb7966ee0f2cc29287ac6127a9babf5bf93884;hb=3efe152e8e2be6f2dc172cf1ac476e2cb01be54b;hp=4bbfe2ee8c029183eea2fdad97edd6843ee8d459;hpb=cfdc1d228b90a65ef26d432b62504ee1c0ab0d04;p=examples%2Fangular-tour-of-heroes diff --git a/src/app/hero-detail/hero-detail.component.ts b/src/app/hero-detail/hero-detail.component.ts index 4bbfe2e..caeb796 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,10 +30,18 @@ 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; + }); }); } + save(): void { + this.heroService.updateHero(this.hero) + .subscribe(() => this.goBack()); + } + goBack(): void { this.location.back(); }