Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the active tab index in Ionic 2?

Tags:

tabs

ionic2

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

like image 669
vedu Avatar asked Dec 08 '22 20:12

vedu


2 Answers

Pass the event object to your method:

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

The event object is actually the selected Tab:

tabSelected(tab: Tab) {
  console.log(tab.index);
}
like image 177
Damir Arh Avatar answered Mar 06 '23 05:03

Damir Arh


Your navController should link to the nested Tab which has a property 'index'.

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

I think this is a little hacky so I'm happy to see other answers. But for the moment you could try that :)

like image 38
Mr.Floppy Avatar answered Mar 06 '23 06:03

Mr.Floppy