Set active/selected tab at start of app


#1

I want to run the function onCreate() every time the create tab is selected.

<ion-tabs class="tabs-icon-top">
  <ion-tab title="Create" icon="icon ion-edit" on-select="onCreate()">
    <ion-nav-view name="tab-create"></ion-nav-view>
  </ion-tab>
  <ion-tab title="Home" icon="icon ion-home" href="#/tab/home">
    <ion-nav-view name="tab-home"></ion-nav-view>
  </ion-tab>
</ion-tabs>

But on-select="" fires when the app first runs as well even though the route for it is not triggered. My guess is that it automatically selects the first tab since I can move the Create tab to second and it doesn’t fire. Is there a way to set some kind of active/selected attribute on the tab that I want first so the create doesn’t fire on init?


#2

I would like to know the answer too…
I have the same problem…


#3

I also have this problem. My tab index that I want selected at the start of the app is inside a variable tabIndex (which was loaded from local IndexedDB when the app started). I can achieve the app’s starting at the proper tab by adding this

this.app.getComponent('nav-tabs').select(tabIndex)

inside onPageWillEnter() of tabs.ts

(the <tabs> tag in tabs.html has id="nav-tabs and preloadTabs="true")

BUT this solution is not great - the very first tab listed in tabs.html always shows up for a split second before the proper tab is selected and that doesn’t look good/professional from a UI/UX point of view.