[Ionic 4] - Get current Tab selected

On Ionic 4 I am not able to understand on how to get the current selected tab… below is the html code …

//HTML
<ion-tabs #myTabs (ionChange)="tabSwitched(myTabs)"></ion-tabs>
//TS 
tabSwitched(myTabs) {
    console.log(myTabs.getSelected());
    // this.events.publish('refresh:channels', Date.now());
  }
//Output comes up like this and I am not sure how to get through the selected Id.

Is this the right approach :slight_smile: or am I doing something wrong here…requesting anyone to please help!

Thanks in advance!

Try:

<ion-tabs>
  <ion-tab tabIcon="contact" [root]="tabCustomers" (ionSelect)="doSomething()"></ion-tab>
</ion-tabs>
1 Like

Thank you so much !!! :slight_smile:

tabs.page.ts

import { IonTabs } from '@ionic/angular';

@ViewChild('myTabs') tabs: IonTabs;

    getSelectedTab(): void {
        this.activeTabName = this.tabs.getSelected();
    }

tabs.page.html

<ion-tabs
    #myTabs
    (ionTabsDidChange)="getSelectedTab()"
>
6 Likes