如何从Angular 2中的辅助路径检索数据

时间:2016-12-01 11:31:05

标签: angular angular2-routing

我的Angular 2项目中有多个router-outlet,如下所示:

<router-outlet></router-outlet>
<router-outlet name="secondary"></router-outlet>
<router-outlet name="third"></router-outlet>

路由信息如下:

{
    path     : 'mainroute',
    component: MainComponent,
    data     : {
        mode: 'normal'
    }
},
{
    path     : 'action',
    component: SecondaryComponent,
    outlet   : 'secondary',
    data     : {
        mode: 'special'
    }
},

例如,如果我有路由localhost:4200/mainroute(secondary:action),我只能从主路由中检索数据,如何从辅助router-outlet检索数据?

export class MainComponent implements {

    constructor (private route: ActivatedRoute) {

        route.data.subscribe((data: any) => {
            console.log(data); // I managed to get the data from main route here
            // how can I subscribe the data from secondary route here
        });
    }
}

0 个答案:

没有答案