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

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

Open
moda-schneij opened this issue Mar 29, 2017 · 0 comments
Assignees

Comments

@moda-schneij
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants