Ionic framework 如何在Ionic2中使用另一页上的按钮切换选项卡?
我不知道如何使用我的Ionic framework 如何在Ionic2中使用另一页上的按钮切换选项卡?,ionic-framework,Ionic Framework,我不知道如何使用我的help.html页面中的按钮打开tab2Root。我在看文件,但没什么 help.html: <button ion-button large clear icon-end color="primary"> Shop <ion-icon name="arrow-forward"></ion-icon> </button> <ion-tabs> <ion-tab [root]="tab1Roo
help.html
页面中的按钮打开tab2Root
。我在看文件,但没什么
help.html:
<button ion-button large clear icon-end color="primary">
Shop <ion-icon name="arrow-forward"></ion-icon>
</button>
<ion-tabs>
<ion-tab [root]="tab1Root" tabTitle="Home" tabIcon="home"></ion-tab>
<ion-tab [root]="tab2Root" tabTitle="Products" tabIcon="search"></ion-tab>
<ion-tab [root]="tab3Root" tabTitle="Cart" tabIcon="cart"></ion-tab>
<ion-tab [root]="tab4Root" tabTitle="Account" tabIcon="person"></ion-tab>
<ion-tab [root]="tab5Root" tabTitle="Help" tabIcon="help-buoy"></ion-tab>
</ion-tabs>
商店
tabs.html:
<button ion-button large clear icon-end color="primary">
Shop <ion-icon name="arrow-forward"></ion-icon>
</button>
<ion-tabs>
<ion-tab [root]="tab1Root" tabTitle="Home" tabIcon="home"></ion-tab>
<ion-tab [root]="tab2Root" tabTitle="Products" tabIcon="search"></ion-tab>
<ion-tab [root]="tab3Root" tabTitle="Cart" tabIcon="cart"></ion-tab>
<ion-tab [root]="tab4Root" tabTitle="Account" tabIcon="person"></ion-tab>
<ion-tab [root]="tab5Root" tabTitle="Help" tabIcon="help-buoy"></ion-tab>
</ion-tabs>
您可以在help.ts类中创建如下函数:
SwitchTab(){
this.navCtrl.parent.select(0); //Selects the first tab
}
<button ion-button large clear icon-end color="primary" (click)="SwitchTab()">
Shop <ion-icon name="arrow-forward"></ion-icon>
</button>
为了使navCtrl对象可用,必须将其与类的构造函数一起注入:
import { NavController } from 'ionic-angular';
...
constructor(private navCtrl: NavController) {
}
不要忘记将按钮绑定到类中的SwitchTab方法,如下所示:
SwitchTab(){
this.navCtrl.parent.select(0); //Selects the first tab
}
<button ion-button large clear icon-end color="primary" (click)="SwitchTab()">
Shop <ion-icon name="arrow-forward"></ion-icon>
</button>
商店