ionic-framework: bug: certain tab methods missing on framework integrations

Bug Report

Ionic version:

[x] 4.11.5

Current behavior: this.tabs.getTab is not a function

Expected behavior: getTab should return tab component

Steps to reproduce: on page with tabs: @ViewChild(IonTabs, { static: false }) tabs: IonTabs; And run this code:

const currentTab = this.tabs.getSelected();
console.log(this.tabs.getTab(currentTab));

This gives error: ERROR TypeError: "this.tabs.getTab is not a function" In console: error TS2339: Property 'getTab' does not exist on type 'IonTabs'.

According to docs: https://ionicframework.com/docs/api/tabs :

getTab
--
Get a specific tab by the value of its tab property or an element reference.
getTab(tab: string \| HTMLIonTabElement) => Promise<HTMLIonTabElement \| undefined>

Related code:

const currentTab = this.tabs.getSelected();
console.log(this.tabs.getTab(currentTab));

Other information:

Ionic info:

Ionic:

   Ionic CLI                     : 5.4.2
   Ionic Framework               : @ionic/angular 4.11.5
   @angular-devkit/build-angular : 0.803.8
   @angular-devkit/schematics    : 8.3.8
   @angular/cli                  : 8.3.19
   @ionic/angular-toolkit        : 2.0.0

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : ios 5.0.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.0, (and 8 other plugins)

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   Android SDK Tools : 26.1.1 
   NodeJS            : v12.13.0 
   npm               : 6.12.0
   OS                : Linux 4.15

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 1
  • Comments: 17 (2 by maintainers)

Most upvoted comments

My use case for the getTab function is to try and attach data to a tab element, then read that data within the ionTabsWillChange event.

It would be super useful to have the online documentation state which frameworks functions and attributes are present/used in, I waste a lot of time trying to do things that turn out to be impossible due to methods and attributes being specific to certain frameworks but no indicators within the documentation.

Dear all,

I can confirm that the issue still exists also for v5.5.4 with VueJS.

I can get the value with property “selectedTab” (not documented) but method “getSelected()” fail with error “is not a function”. Same for “select()”.

Do you have any plan to resolve this? Seems that VUEJS integration is too buggy for production.

@liamdebeasi may i politely bring this back to your attention? While adding features to our Ionic app i bumped into the hacks i implemented to workaround this issue. Our case is still simply to reset the navigation stack for tabs on certain events (since previously navigated routes become invalid). Short of reloading the whole app there is no straightforward way to do this (that i know of). Regardless of our use case - the documentation of Ionic 7 still lists getting tabs instances as a documented feature (even so the missing implementation was reported 3 1/2 years ago).

I was able to hack a reset feature by writing to an undocumented property directly:

tabs.outlet.stackCtrl.views = []

This causes Ionic to (re-)load the default route for each tab when clicking on a tab-button. From what i see this isn’t causing any runtime errors, however obviously this may fail randomly.

Any suggestion on how to better implement this?

the problem “Property ‘getTab’ does not exist on type ‘IonTabs’.” is not solved yet?

This issue continues to exist in Ionic v6.18.2 with Angular :

import { IonTabs } from '@ionic/angular';
// ...
this.tabs.getTab(this.tabs.getSelected());
// Property 'getTab' does not exist on type 'IonTabs'.

ion-tabs.d.ts :

export declare class IonTabs {
    private navCtrl;
    outlet: IonRouterOutlet;
    tabBar: IonTabBar | undefined;
    ionTabsWillChange: EventEmitter<{
        tab: string;
    }>;
    ionTabsDidChange: EventEmitter<{
        tab: string;
    }>;
    constructor(navCtrl: NavController);
    onPageSelected(detail: StackEvent): void;
    select(tabOrEvent: string | CustomEvent): Promise<boolean> | undefined;
    getSelected(): string | undefined;
    static ɵfac: i0.ɵɵFactoryDeclaration<IonTabs, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<IonTabs, "ion-tabs", never, {}, { "ionTabsWillChange": "ionTabsWillChange"; "ionTabsDidChange": "ionTabsDidChange"; }, ["tabBar"], ["[slot=top]", "*"]>;
}

There’s no IonTab.getTab() while it’s in the documentation. I need it to change a tab’s icon.