0

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.

elpddev
  • 4,314
  • 4
  • 26
  • 47
  • You can use a parent component, which will resolve the params and pass them to an independent child component. https://angular.io/guide/component-interaction – Rajesh Dan Aug 04 '17 at 11:06
  • @RajeshDan Thank you. I thought about that but that requires that mediator component the be able to activate dynamic component, getting the name and binding logic in the data param of the router, or build each component a special mediator that wrap around it. Both of those options are sub optimal for my case. – elpddev Aug 04 '17 at 11:10
  • in that case I wonder is there any way to achieve what you wanted, as far as I know. Will update if found any. Thanks – Rajesh Dan Aug 04 '17 at 11:15

0 Answers0