This repository was archived by the owner on Dec 4, 2017. It is now read-only.
This repository was archived by the owner on Dec 4, 2017. It is now read-only.
Routing docs should use idiomatic Observable syntax #2675
Closed
Description
Ref: https://angular.io/docs/ts/latest/tutorial/toh-pt5.html
current example:
ngOnInit(): void {
this.route.params.forEach((params: Params) => {
let id = +params['id'];
this.heroService.getHero(id)
.then(hero => this.hero = hero);
});
}
This is rather hard to parse (and not exactly side effect free)
Better syntax would be
this.routeParams.flatMap(params => this.heroService.getHero(params.id))
or
this.routeParams.switchMap(params => this.heroService.getHero(params.id))
which would cancel in flight requests - the current syntax has the possibility of an inflight request arriving after the user navigates away.
Note that .switch/flatMap can accept a Promise or an Observable, so its a good place to show interop.
Metadata
Metadata
Assignees
Labels
No labels