Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework 如何在Ionic2中使用另一页上的按钮切换选项卡?_Ionic Framework - Fatal编程技术网

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>

商店