我試着去獲得:在如何獲得:孩子航線的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碼回答你真正想要的東西。我更新了我的答案。 –
完美,它的工作原理,謝謝 –