2017-08-15 29 views
0

我一直在尝试从使用路由ActivatedRoute模块的命名路由获得第二个路由出口。 e.g是否有可能在辅助出口Angular 2中获得主要路由出口参数?

当前网址:http://localhost:4200/dashboard/contraceptives/(assessment:5991780301d88a211e86e012//details:599062793f86454d43896255)

网点:

<div class="col m4 z-depth-3"> 
    <router-outlet name="details"></router-outlet> 
</div> 
<div class="col m4 z-depth-3"> 
    <router-outlet name="assessment"></router-outlet> 
</div> 

组件:

我怎样才能在当前的出口和组件的细节PARAMS?

ngOnInit() { 
    this.sub = this.route.params.subscribe(params => { 
     this.id = params['id']; 
    }); 
    } 
+0

需要[穿越激活途径(https://angular.io/api/router/ActivatedRoute#parent) –

回答

-1

我设法找到了一种方法:

constructor(router:Router){ 
    RouterLinks.events(event=>{ 
     // here i am subscribing to the events 
     const primaryRouter = event.state.root.firstChild; 
     // where first child is the primary router-outlet 
    }) 
} 
+0

欢迎SO,请解释你的答案。不要只发布代码片段 – cSteusloff