How to get active tab index in Ionic 2?

Is there a way to get the index of the active tab in Ionic 2? I searched in Ionic 1 there is $ ionicTabsDelegate.

+4
source share
2 answers

Pass the event object to your method:

<ion-tabs (ionChange)="tabSelected($event)">

The event object is actually selected Tab:

tabSelected(tab: Tab) {
  console.log(tab.index);
}
+5
source

Your navController must reference a nested Tab that has the 'index' property.

console.log((<Tab>this.navCtrl).index);

I think this is a bit hacky, so I'm glad to see other answers. But for now, you can try the following :)

+3
source

Source: https://habr.com/ru/post/1658529/


All Articles