在Ionic 2中选择特定选项卡

Kay*_*Zee 9 ionic2

我正在尝试使用Ionic 2,我仍在努力完成大多数基本任务,例如在加载应用程序时选择一个标签.

我试图注入Tabs控制器并打电话selectonPageLoaded事件,但无济于事.

有人可以帮忙吗?

Mas*_*200 9

要默认使用ionic 2中的选项卡,请更改selectedIndex属性:

<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>
Run Code Online (Sandbox Code Playgroud)

页面加载时,"关于"选项卡将成为选定的选项卡.


小智 6

//importing tabs for manipuling our ion-tabs
import {Tabs} from 'ionic-angular';
@Page({
    templateUrl: 'build/pages/page1/page1.html'
})
export class Page1 
{
    //provide Angular with metadata about things it should inject in the constructor
    static get parameters()
    {
        return [[Tabs]];
    }
    //after injecting ,passing an instance of [Tabs] in the page constructor 
    constructor(tab) {
        this.tab = tab;   
    }
    //"onPageWillEnter" function fires every time a page becomes the active      view.
    onPageWillEnter()
    {
        //make the second tab selected From the first tab (within the current Page 'page1')
        // 1 IS the index of the target tab
        this.tab.select(1);
    }
}
Run Code Online (Sandbox Code Playgroud)


Pat*_*cow 6

尝试

var t: Tabs = this.nav.parent;
t.select(index);
Run Code Online (Sandbox Code Playgroud)