docs(toh): add instructions to add the goBack method

closes #1478
This commit is contained in:
Foxandxss 2016-05-23 14:55:37 +02:00 committed by Ward Bell
parent 129b34c77e
commit 508b779a41
2 changed files with 13 additions and 6 deletions

View File

@ -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
}

View File

@ -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