Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 508b779

Browse files
Foxandxsswardbell
authored andcommitted
docs(toh): add instructions to add the goBack method
closes #1478
1 parent 129b34c commit 508b779

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

public/docs/_examples/toh-6/ts/app/hero-detail.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ export class HeroDetailComponent implements OnInit {
4646
.catch(error => this.error = error); // TODO: Display error message
4747
}
4848
// #enddocregion save
49+
// #docregion goback
4950
goBack(savedHero: Hero = null) {
5051
this.close.emit(savedHero);
5152
if (this.navigated) { window.history.back(); }
5253
}
54+
// #enddocregion goback
5355
}
5456

public/docs/ts/latest/tutorial/toh-pt6.jade

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,24 @@ code-example(format="." language="bash").
220220
### Add/Edit in the *HeroDetailComponent*
221221
We already have `HeroDetailComponent` for viewing details about a specific hero. Add and Edit are natural extensions of the detail view, so we are able to reuse `DetailHeroComponent` with a few tweaks. The original component was created to render existing data, but to add new data we have to initialize the `hero` property to an empty `Hero` object.
222222

223-
+makeExample('toh-6/ts/app/hero-detail.component.ts', 'ngOnInit', 'app/hero-detail.component.ts (ngOnInit)')(format=".")
223+
+makeExample('toh-6/ts/app/hero-detail.component.ts', 'ngOnInit', 'app/hero-detail.component.ts (ngOnInit)')(format=".")
224224

225225
:marked
226226
In order to differentiate between add and edit we are adding a check to see if an id is passed in the url. If the id is absent we bind `HeroDetailComponent` to an empty `Hero` object. In either case, any edits made through the UI will be bound back to the same `hero` property.
227227

228228
The next step is to add a save method to `HeroDetailComponent` and call the corresponding save method in `HeroesService`.
229229

230-
+makeExample('toh-6/ts/app/hero-detail.component.ts', 'save', 'app/hero-detail.component.ts (save)')(format=".")
230+
+makeExample('toh-6/ts/app/hero-detail.component.ts', 'save', 'app/hero-detail.component.ts (save)')(format=".")
231231

232232
:marked
233233
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.
234234

235-
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.
235+
After we save a hero, we redirect the browser back to the to the previous page using the `goBack()` method.
236+
237+
+makeExample('toh-6/ts/app/hero-detail.component.ts', 'goback', 'app/hero-detail.component.ts (goBack)')(format=".")
238+
239+
:marked
240+
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.
236241

237242
.l-sub-section
238243
:marked
@@ -242,7 +247,7 @@ code-example(format="." language="bash").
242247
Here is `HeroDetailComponent` with its new save button.
243248

244249
figure.image-display
245-
img(src='/resources/images/devguide/toh/hero-details-save-button.png' alt="Hero Details With Save Button")
250+
img(src='/resources/images/devguide/toh/hero-details-save-button.png' alt="Hero Details With Save Button")
246251

247252
:marked
248253
### Add/Delete in the *HeroesComponent*
@@ -254,12 +259,12 @@ figure.image-display
254259
As we noted above, that is the component's cue to create and present an empty hero.
255260

256261
Add the following HTML to the `heroes.component.html`, just below the hero list (the `*ngFor`).
257-
+makeExample('toh-6/ts/app/heroes.component.html', 'add-hero', 'app/heroes.component.ts (add)')(format=".")
262+
+makeExample('toh-6/ts/app/heroes.component.html', 'add-hero', 'app/heroes.component.ts (add)')(format=".")
258263
:marked
259264
The user can *delete* an existing hero by clicking a delete button next to the hero's name.
260265

261266
Add the following HTML to the `heroes.component.html` right after the name in the repeated `<li>` tag:
262-
+makeExample('toh-6/ts/app/heroes.component.html', 'delete-hero', 'app/heroes.component.ts (delete)')(format=".")
267+
+makeExample('toh-6/ts/app/heroes.component.html', 'delete-hero', 'app/heroes.component.ts (delete)')(format=".")
263268

264269
:marked
265270
Now let's fix-up the `HeroesComponent` to support the *add* and *delete* actions in the template.

0 commit comments

Comments
 (0)