首页 > 解决方案 > how to navigate to specific tabs index from other page(dont have tab originally) in ionic 3?

问题描述

I have a page name EatPage that doesn't have any tabs on it. What I want to do is to navigate from MyPage to tab bar index 2 and pass parameter from EatPage.

I have tried using this code to pass parameter

opentab2(id: string) {
    this.navCtrl.push('TabsPage', {
      docId: id
}); 

but don't know how to change tab from here.

标签: ionic-framework

解决方案


If you are talking about Ionic Tabs, then syntax is like this.

TabsPage

@Component({
    templateUrl: 'tabs.html'
})
export class TabsPage {
  fooId:any;
  constructor() {

      this.fooId = "some-value";

      // this tells the tabs component which Pages should be each tab's root Page
      this.tab1Root = Tab1;
      this.tab2Root = Tab2;
      this.tab3Root = Tab3;
    }
}

Page

<ion-tabs>
    <ion-tab tabTitle="Tab1" [root]="tab1Root" [rootParams]="fooId"></ion-tab>
    <ion-tab tabTitle="Tab2" [root]="tab2Root" [rootParams]="fooId"></ion-tab>
    <ion-tab tabTitle="Tab3" [root]="tab3Root" [rootParams]="fooId"></ion-tab>
</ion-tabs>

else if you want to pass values i would suggest to use services. Tell me if you want to know how its done via services.ill share the code here.

Read more here and official docs


推荐阅读