Angular 2: getting RouteParams from parent component

前端 未结 13 911
暖寄归人
暖寄归人 2020-11-28 04:47

How do I get the RouteParams from a parent component?

App.ts:

@Component({
  ...
})

@RouteConfig([
  {path: \'/\', component: HomeCompo         


        
13条回答
  •  醉梦人生
    2020-11-28 05:18

    In FINAL with little help of RXJS you can combine both maps (from child and parent):

    (route) => Observable
        .zip(route.params, route.parent.params)
        .map(data => Object.assign({}, data[0], data[1]))
    

    Other questions one might have:

    • Is it really a good idea to use above - because of coupling (couple child component with parent's param's - not on api level - hidden coupling),
    • Is it proper approach in term of RXJS (it would require hardcore RXJS user feedback ;)

提交回复
热议问题