-
Notifications
You must be signed in to change notification settings - Fork 875
docs(toh): Replaced window.history with location service #2439
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// #docregion | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ActivatedRoute, Params } from '@angular/router'; | ||
import { Location } from '@angular/common'; | ||
|
||
import { Hero } from './hero'; | ||
import { HeroService } from './hero.service'; | ||
|
@@ -15,8 +16,9 @@ export class HeroDetailComponent implements OnInit { | |
|
||
constructor( | ||
private heroService: HeroService, | ||
private route: ActivatedRoute) { | ||
} | ||
private route: ActivatedRoute, | ||
private location: Location | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.route.params.forEach((params: Params) => { | ||
|
@@ -29,11 +31,11 @@ export class HeroDetailComponent implements OnInit { | |
// #docregion save | ||
save(): void { | ||
this.heroService.update(this.hero) | ||
.then(this.goBack); | ||
.then(() => this.goBack()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change? You are replacing a function g by an anonymous function which does nothing but call g. I.e., g and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It throws an error of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, your change is actually the right thing to do to ensure that |
||
} | ||
// #enddocregion save | ||
|
||
goBack(): void { | ||
window.history.back(); | ||
this.location.back(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.