angular.io icon indicating copy to clipboard operation
angular.io copied to clipboard

Test a routed component with parameters, example and aside don't match TOH code

Open moda-schneij opened this issue 7 years ago • 0 comments

Test a routed component with parameters has a code snippet of subscribing to ActivatedRoute params and using the "id" parameter to get a hero from a getHero method.

ngOnInit(): void {
  // get hero when `id` param changes
  this.route.params.subscribe(p => this.getHero(p && p['id']));
}

The actual TOH code uses a switchMap, calls the HeroService, then subscribes to the returned hero.

ngOnInit(): void {
    this.route.params
      .switchMap((params: Params) => this.heroService.getHero(+params['id']))
      .subscribe(hero => this.hero = hero);
  }

The aside below this code snippet refers to a forEach, a pluck, and a catch, none of which are used in the example or actual code.

All of this is confusing. The aside should probably be removed and the code snippet updated to match the latest TOH code.

moda-schneij avatar Mar 29 '17 23:03 moda-schneij