Select a specific tab in Ionic 2

后端 未结 4 926
鱼传尺愫
鱼传尺愫 2021-02-14 17:22

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

4条回答
  •  感动是毒
    2021-02-14 17:43

    //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);
        }
    }
    

提交回复
热议问题