My app features a side menu with tabs, following a structure similar to .
The root of my app is Menu.ts, where I load the Tabs Pages.
In the constructor of app.component, I am trying to get the current active tab using various methods like:
this.nav.getActive().component
this.nav.getActive().component.tabRef.getSelected().root
like this
this.app.viewDidEnter.subscribe((evt) => {
this.nav.getActive().component
});
However, none of these methods are working as expected. They always return TabsPage instead of the actual name of the active page.
This is how the Tabs Page is structured:
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;
}
}
And here is the template for the Tabs:
<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>