Angular 2 @angular/router 3.0.0-alpha.7 - Accessing Multiple Parameters

妖精的绣舞 提交于 2019-12-06 14:27:43

One way you could do it is using Parameter handling and Destructuring like this:

this.activatedRoute.params
  .map(params => [params['id'], params['p2'], params['p3']]) <== pass desired array
  .subscribe(([id, p2, p3]) => { <== destructuring params
      //use param id, p2 or p3
   });

See also HeroDetailComponent component here http://plnkr.co/edit/JtuOAZsZPhkn1CISQaO9?p=preview

Or you can write a bit simple:

this.activatedRoute.params
  .subscribe(({id, p2, p3}) => { <== destructuring params
      //use param id, p2 or p3
   });

Plunker sample (HeroDetailComponent)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!