我试着去获得:在如何获得:孩子航线的ID PARAM从父组件在Angular2
RouterModule.forRoot([
{
path: 'orders',
component: ListComponent,
children: [
{
path: 'view/:id',
component: ViewComponent
},
]
}
])
从ListComponent定义ID PARAM。
我已经尝试:
route: ActivatedRoute
route.params.subscribe(params => {
let id = +params['id'];
})
从ListComponent,但参数数组是空的,我想它,因为:ID参数所属到viewComponent不listComponent
我怎样才能在ID PARAM listComponent?
看起来像属性routerState不存在ActivatedRoute,我也想获得父组件中的id不是子组件,所以我用route.firstChild.params –
我误解了这个问题,并假设@run码回答你真正想要的东西。我更新了我的答案。 –
完美,它的工作原理,谢谢 –