gpt4 book ai didi

angular - 如何在 Ionic 3 的 app.module 中获取当前事件选项卡名称

转载 作者:搜寻专家 更新时间:2023-10-30 21:59:35 24 4
gpt4 key购买 nike

我的应用程序有侧边菜单+选项卡,结构类似于 https://devdactic.com/ionic-side-menu-tabs/

Menu.ts 是我的应用程序的根,它在我正在加载标签页的那个模块中

我想在 app.component 的构造函数中获取当前事件选项卡,我已经尝试了以下方法和其他一些方法

this.nav.getActive().component
this.nav.getActive().component.tabRef.getSelected().root

like this
this.app.viewDidEnter.subscribe((evt) => {
this.nav.getActive().component

});

这些都不起作用。它总是返回 TabsPage 而不是当前事件的页面名称。

标签页

export class TabsPage {

tab1Root: any = 'HomePage';
tab2Root: any = 'ProductsPage';
tab3Root: any = 'DynamicProductsPage';
myIndex: number;

constructor(public navCtrl: NavController, public navParams: NavParams) {
this.myIndex = navParams.data.tabIndex || 0;
}

}

标签模板

<ion-tabs  #myTabs [selectedIndex]="myIndex" [color]="'primary'">
<ion-tab [root]="tab1Root" tabTitle="Home" tabIcon="ios-home" show=true md="md-home"></ion-tab>
<ion-tab [root]="tab2Root" tabTitle="Products" tabIcon="ios-laptop" show=true md="md-laptop"></ion-tab>
</ion-tabs>

最佳答案

您可以尝试如下所示。

export class TabsPage {

@ViewChild('myTabs') tabRef: Tabs;

ionViewDidEnter() {
let tab:Tab = this.tabRef.getSelected();//Returns the currently selected tab
}

}

您可以阅读更多关于 it here 的信息.

如果您需要将此详细信息发送到 app.component.ts,那么只需使用 Events .使用 Events,您可以将上述详细信息(即 tab)发送到 app.component.ts

关于angular - 如何在 Ionic 3 的 app.module 中获取当前事件选项卡名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46723267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com