本文介绍了Angular2(rc4)-检查父组件中的活动子路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检查父级组件中的活动子路由,但遇到了困难.

I am trying to check the active child route in a parent component, but I am having difficulties with it.

我尝试通过执行以下操作来订阅ActivatedRoute:

I have tried to subscribe to the ActivatedRoute by doing something like this:

class ParentComponent {
    constructor(private _route:ActivatedRoute) {}

    ngOnInit() {
        this._route.data.subscribe(value => console.log(value)});
    }
}

我已经阅读了很多有关Stack Overflow的线程,但是找不到解决方案来检查父组件的子路由并对其进行更新.

I have read a lot of threads on Stack Overflow, but can't find a solution that checks and gets updated regarding the child routes of a parent component.

有什么想法吗?

推荐答案

您可以使用以下代码段访问活动的子路由

You can access active child route using below code snippet

constructor(private router:Router, private currentActivatedRoute:ActivatedRoute)
// this should be called in ngOnInit
    var state = this.router.routerState
    var children = state.children(this.currentActivatedRoute)

RouterState

这篇关于Angular2(rc4)-检查父组件中的活动子路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 13:32