projects
/
examples
/
angular-tour-of-heroes
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
WIP: 6: Get Data from a Server k) Search by name
[examples/angular-tour-of-heroes]
/
src
/
app
/
hero-detail
/
hero-detail.component.ts
diff --git
a/src/app/hero-detail/hero-detail.component.ts
b/src/app/hero-detail/hero-detail.component.ts
index
4bbfe2e
..
caeb796
100644
(file)
--- 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 { HeroService } from '../hero.service';
import { Hero } from '../hero';
+import { MessageService } from '../message.service';
@Component({
selector: 'app-hero-detail',
@Component({
selector: 'app-hero-detail',
@@
-17,6
+18,7
@@
export class HeroDetailComponent implements OnInit {
constructor(
private route: ActivatedRoute,
private heroService: HeroService,
constructor(
private route: ActivatedRoute,
private heroService: HeroService,
+ private messageService: MessageService,
private location: Location
) { }
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.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();
}
goBack(): void {
this.location.back();
}