Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select a specific tab in Ionic 2

Tags:

ionic2

I'm trying to use the Ionic 2 and I'm still struggling with most basic tasks, such as select a tab when the app is loading.

I've tried to inject the Tabs controller and call select on the onPageLoaded event, but to no avail.

Can someone help maybe?

like image 725
KayZee Avatar asked Jan 08 '16 11:01

KayZee


3 Answers

In Ionic 3 and angular 4.

import { Tabs } from 'ionic-angular/navigation/nav-interfaces';
@ViewChild('myTabs') tabRef: Tabs; - With in the class about constructor.
this.tabRef.select(0, {}); // In the method where you want set tab.
like image 164
Keerthesh Avatar answered Sep 20 '22 18:09

Keerthesh


try

var t: Tabs = this.nav.parent;
t.select(index);
like image 31
Patrioticcow Avatar answered Sep 18 '22 18:09

Patrioticcow


To default to a tab in ionic 2 change the selectedIndex property:

<ion-tabs [selectedIndex]="1">
      <ion-tab [root]="tab1Root" tabTitle="Home" tabIcon="rewind"></ion-tab> <!-- Index 0-->
      <ion-tab [root]="tab2Root" tabTitle="About" tabIcon="md-time"></ion-tab><!-- Index 1 (Selected)-->
      <ion-tab [root]="tab3Root" tabTitle="Contacts" tabIcon="fastforward"></ion-tab><!-- Index 2-->
</ion-tabs>

The About tab will be the selected tab when the page loads.

like image 44
MasterProgrammer200 Avatar answered Sep 20 '22 18:09

MasterProgrammer200