parent
129b34c77e
commit
508b779a41
|
@ -46,9 +46,11 @@ export class HeroDetailComponent implements OnInit {
|
|||
.catch(error => this.error = error); // TODO: Display error message
|
||||
}
|
||||
// #enddocregion save
|
||||
// #docregion goback
|
||||
goBack(savedHero: Hero = null) {
|
||||
this.close.emit(savedHero);
|
||||
if (this.navigated) { window.history.back(); }
|
||||
}
|
||||
// #enddocregion goback
|
||||
}
|
||||
|
||||
|
|
|
@ -232,7 +232,12 @@ code-example(format="." language="bash").
|
|||
:marked
|
||||
The same save method is used for both add and edit since `HeroService` will know when to call `post` vs `put` based on the state of the `Hero` object.
|
||||
|
||||
Earlier we used the `save()` method to return a promise, so when the promise resolves, we call `emit` to notify `HeroesComponent` that we just added or modified a hero. `HeroesComponent` is listening for this notification and will automatically refresh the list of heroes to include our recent updates.
|
||||
After we save a hero, we redirect the browser back to the to the previous page using the `goBack()` method.
|
||||
|
||||
+makeExample('toh-6/ts/app/hero-detail.component.ts', 'goback', 'app/hero-detail.component.ts (goBack)')(format=".")
|
||||
|
||||
:marked
|
||||
Here we call `emit` to notify that we just added or modified a hero. `HeroesComponent` is listening for this notification and will automatically refresh the list of heroes to include our recent updates.
|
||||
|
||||
.l-sub-section
|
||||
:marked
|
||||
|
|
Loading…
Reference in New Issue