elpddev
elpddev

Reputation: 4494

Having router in angular 2 update the component inputs instead of using the params observers

In angular router, in order to get parameters from the outside activator and the router, I use the paramMap and queryParamMap:

ngOnInit() {
  this.route.paramMap
    .switchMap((params: ParamMap) =>
      this.service.getHero(params.get('id')))
    .subscribe((hero: Hero) => this.hero = hero);
}

That force the component architecture to be aware it is operated from a router-outlet and a router manager.

Instead, is there a way to specify in the routes configuration, a way to map route params to component inputs, so the component could be used without modification also in regular template binding? Something like mapping the id parameter to the id component input parameter for instance.

Upvotes: 0

Views: 123

Answers (0)

Related Questions