我正在尝试使用Ionic 2,我仍在努力完成大多数基本任务,例如在加载应用程序时选择一个标签.
我试图注入Tabs
控制器并打电话select
给onPageLoaded
事件,但无济于事.
有人可以帮忙吗?
要默认使用ionic 2中的选项卡,请更改selectedIndex属性:
页面加载时,"关于"选项卡将成为选定的选项卡.
//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); } }
尝试
var t: Tabs = this.nav.parent; t.select(index);