docs: Updated router guide content and examples for paramMap
and queryParamMap, tracing, and incidental improvements. closes #16991 and #16259 which it also fixes.
This commit is contained in:

committed by
Matias Niemelä

parent
4268c82898
commit
8d01db4638
@ -5,7 +5,7 @@
|
||||
// #docregion added-imports
|
||||
// Keep the Input import for now, you'll remove it later:
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Params } from '@angular/router';
|
||||
import { ActivatedRoute, ParamMap } from '@angular/router';
|
||||
import { Location } from '@angular/common';
|
||||
|
||||
import { HeroService } from './hero.service';
|
||||
@ -17,7 +17,7 @@ import { Hero } from './hero';
|
||||
@Component({})
|
||||
export class HeroDetailComponent implements OnInit {
|
||||
@Input() hero: Hero;
|
||||
bogus: Params;
|
||||
bogus: ParamMap;
|
||||
|
||||
constructor(
|
||||
private heroService: HeroService,
|
||||
|
@ -2,9 +2,9 @@
|
||||
// #docregion , v2, rxjs-import
|
||||
import 'rxjs/add/operator/switchMap';
|
||||
// #enddocregion rxjs-import
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Params } from '@angular/router';
|
||||
import { Location } from '@angular/common';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, ParamMap } from '@angular/router';
|
||||
import { Location } from '@angular/common';
|
||||
|
||||
import { Hero } from './hero';
|
||||
import { HeroService } from './hero.service';
|
||||
@ -32,8 +32,8 @@ export class HeroDetailComponent implements OnInit {
|
||||
|
||||
// #docregion ngOnInit
|
||||
ngOnInit(): void {
|
||||
this.route.params
|
||||
.switchMap((params: Params) => this.heroService.getHero(+params['id']))
|
||||
this.route.paramMap
|
||||
.switchMap((params: ParamMap) => this.heroService.getHero(+params.get('id')))
|
||||
.subscribe(hero => this.hero = hero);
|
||||
}
|
||||
// #enddocregion ngOnInit
|
||||
|
Reference in New Issue
Block a user