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

Commit 556e406

Browse files
brandonrobertswardbell
authored andcommitted
docs(toh): Replaced window.history with location service (#2439)
1 parent 9970094 commit 556e406

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
// #docregion added-imports
66
// Keep the Input import for now, we'll remove it later:
77
import { Component, Input, OnInit } from '@angular/core';
8-
import { ActivatedRoute, Params } from '@angular/router';
8+
import { ActivatedRoute, Params } from '@angular/router';
9+
import { Location } from '@angular/common';
910

1011
import { HeroService } from './hero.service';
1112
// #enddocregion added-imports
@@ -20,8 +21,9 @@ export class HeroDetailComponent implements OnInit {
2021

2122
constructor(
2223
private heroService: HeroService,
23-
private route: ActivatedRoute) {
24-
}
24+
private route: ActivatedRoute,
25+
private location: Location
26+
) {}
2527

2628
ngOnInit() {}
2729
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// #docplaster
22
// #docregion , v2
3-
import { Component, OnInit } from '@angular/core';
3+
import { Component, OnInit } from '@angular/core';
44
import { ActivatedRoute, Params } from '@angular/router';
5+
import { Location } from '@angular/common';
56

6-
import { Hero } from './hero';
7-
import { HeroService } from './hero.service';
7+
import { Hero } from './hero';
8+
import { HeroService } from './hero.service';
89

910
@Component({
1011
moduleId: module.id,
@@ -23,8 +24,9 @@ export class HeroDetailComponent implements OnInit {
2324
// #docregion ctor
2425
constructor(
2526
private heroService: HeroService,
26-
private route: ActivatedRoute) {
27-
}
27+
private route: ActivatedRoute,
28+
private location: Location
29+
) {}
2830
// #enddocregion ctor
2931

3032
// #docregion ngOnInit
@@ -39,7 +41,7 @@ export class HeroDetailComponent implements OnInit {
3941

4042
// #docregion goBack
4143
goBack(): void {
42-
window.history.back();
44+
this.location.back();
4345
}
4446
// #enddocregion goBack
4547
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// #docregion
2-
import { Component, OnInit } from '@angular/core';
2+
import { Component, OnInit } from '@angular/core';
33
import { ActivatedRoute, Params } from '@angular/router';
4+
import { Location } from '@angular/common';
45

56
import { Hero } from './hero';
67
import { HeroService } from './hero.service';
@@ -16,8 +17,9 @@ export class HeroDetailComponent implements OnInit {
1617

1718
constructor(
1819
private heroService: HeroService,
19-
private route: ActivatedRoute) {
20-
}
20+
private route: ActivatedRoute,
21+
private location: Location
22+
) {}
2123

2224
ngOnInit(): void {
2325
this.route.params.forEach((params: Params) => {
@@ -30,11 +32,11 @@ export class HeroDetailComponent implements OnInit {
3032
// #docregion save
3133
save(): void {
3234
this.heroService.update(this.hero)
33-
.then(this.goBack);
35+
.then(() => this.goBack());
3436
}
3537
// #enddocregion save
3638

3739
goBack(): void {
38-
window.history.back();
40+
this.location.back();
3941
}
4042
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ figure.image-display
2424
img(src='/resources/images/devguide/toh/nav-diagram.png' alt="View navigations")
2525

2626
:marked
27-
We'll add Angular’s *Component Router* to our app to satisfy these requirements.
27+
We'll add Angular’s *Router* to our app to satisfy these requirements.
2828

2929
.l-sub-section
3030
:marked
@@ -166,7 +166,7 @@ block app-comp-v1
166166
Instead of displaying heroes automatically, we'd like to show them *after* the user clicks a button.
167167
In other words, we'd like to navigate to the list of heroes.
168168

169-
We'll need the Angular *Component Router*.
169+
We'll need the Angular *Router*.
170170

171171
block angular-router
172172
:marked
@@ -517,7 +517,7 @@ block route-params
517517

518518
- var _ActivatedRoute = _docsFor == 'dart' ? 'RouteParams' : 'ActivatedRoute'
519519
:marked
520-
Let's have the `!{_ActivatedRoute}` service and the `HeroService` injected
520+
Let's have the `!{_ActivatedRoute}` service, the `HeroService` and the `Location` service injected
521521
into the constructor, saving their values in private fields:
522522

523523
+makeExcerpt('app/hero-detail.component.ts (constructor)', 'ctor')
@@ -563,7 +563,8 @@ block extract-id
563563
How do we navigate somewhere else when we're done?
564564

565565
The user could click one of the two links in the `AppComponent`. Or click the browser's back button.
566-
We'll add a third option, a `goBack` method that navigates backward one step in the browser's history stack.
566+
We'll add a third option, a `goBack` method that navigates backward one step in the browser's history stack
567+
using the `Location` service we injected previously.
567568

568569
+makeExcerpt('app/hero-detail.component.ts', 'goBack')
569570

@@ -894,7 +895,7 @@ block file-tree-end
894895

895896
We travelled a great distance in this chapter
896897

897-
- We added the Angular *Component Router* to navigate among different components.
898+
- We added the Angular *Router* to navigate among different components.
898899
- We learned how to create router links to represent navigation menu items.
899900
- We used router link parameters to navigate to the details of user selected hero.
900901
- We shared the `HeroService` among multiple components.

0 commit comments

Comments
 (0)