当前位置:  开发笔记 > 前端 > 正文

在Ionic 2中选择特定选项卡

如何解决《在Ionic2中选择特定选项卡》经验,为你挑选了3个好方法。

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

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

有人可以帮忙吗?



1> MasterProgra..:

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


       
      
      

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



2> 小智..:
//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);
    }
}



3> Patrioticcow..:

尝试

var t: Tabs = this.nav.parent;
t.select(index);

推荐阅读
TXCWB_523
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有