如何从父路由器或父路由器检查活动子路由器?

2023-12-28

如何检查子路由器是否活动,在角度4中显示状态真或假,
现在我正在使用: /* @角度/cli:1.4.4 节点:8.6.0 打字稿:2.3.4 @角度/路由器:4.4.4 */

我的家长路线是:

const routes:Routes=[
    {
        path: '', component: SummaryOfFindingsComponent,
        children:[
            {
                path:'data-time-frame', component: DataTimeFrameComponent
            },
            {
                path:'email-address', component: EmailAddressesComponent
            },
            {
                path:'repair-orders', component: RepairOrdersComponent
            },
            {
                path:'total-records', component:TotalRecordsComponent
            },
            {
                path:'unique-households', component: UniqueHouseholdsComponent
            },
            {
                path:'unique-vins', component: UniqueVinsComponent
            }
        ]
    }
]

父组件是:

export class SummaryOfFindingsComponent implements OnInit {
    isUserSelected;
    constructor() { this.isUserSelected=false; }
    ngOnInit() { }
    isUserItemSelect(){
        this.isUserSelected=true;
    }
}

导入你的父组件.ts

import { ActivatedRoute } from '@angular/router';

和生命周期挂钩 ngOnInit() 并创建 Refarence 的 ActivatedRoute

constructor(private activeRouter:ActivatedRoute) {}

并在此处的 ngOnInit 函数中编写一些代码。

ngOnInit() {
    var _activeChild = this.activeRouter.children.length;
    if (_activeChild!=0) {
        //your active children 1 or more than children then active 1,otherwise it is 0
    }
}

注意:此代码正在我的应用程序中运行(谢谢)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从父路由器或父路由器检查活动子路由器? 的相关文章

随机推荐