routerState.parent的替代品,在angular2中不再存在

时间:2016-09-15 13:00:41

标签: javascript html angularjs angular angular2-routing

在angular2 rc5中,我有这段代码。

this.router.routerState.parent(this.route).params.forEach((params: Params) => {
    url = params['url'];
    id = +params['id'];
});

我不得不使用这个,因为我的路由器上有两个级别,因为某些原因这样做不起作用。

this.route.params.forEach((params: Params) => {
        url = params['url'];
        id = +params['id'];
    });

我仍然很乐意这样做,但在angular2中,路由器状态上不再存在.parent方法。

我可以实现我想要的,但使用角度2.0.0中提供的其他方法吗?

1 个答案:

答案 0 :(得分:4)

如果这有助于其他任何人。而不是使用.routerState只需使用.parent

// parent params
let url = '';
let id = 0;
this.route.parent.params.forEach((params: Params) => {
    url = params['url'];
    id = +params['id'];
});