如何从父路由器或父路由器检查活动子路由器? [英] how to check active child router from parent router or parent router against?
本文介绍了如何从父路由器或父路由器检查活动子路由器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何可能检查子路由器是否活动,在 angular 4 中显示状态为真或假,
现在我正在使用:/*@角度/cli:1.4.4节点:8.6.0打字稿:2.3.4@角度/路由器:4.4.4*/
How to possible check Children Router Active Or Not, Show The status true or false in angular 4,
Now currently I'm use :
/*
@angular/cli: 1.4.4
node: 8.6.0
typescript: 2.3.4
@angular/router: 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 Of ActivatedRoute
and life cycle hooks ngOnInit() And create Refarence Of ActivatedRoute
constructor(private activeRouter:ActivatedRoute) {}
并在此处的 ngOnInit 函数中编写一些代码..
And Write Some code in your ngOnInit functions here..
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
}
}
注意:此代码正在运行我的应用程序(谢谢)
Note: This code is working my app ( Thank You )
这篇关于如何从父路由器或父路由器检查活动子路由器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文