Ionic 2 passing tabs NavParams to tab

前端 未结 5 619
名媛妹妹
名媛妹妹 2020-12-04 23:43

I\'m starting out on creating my first app using Ionic 2 and through a lot of trial and error have got to a point where no number of Google searching can find anything to

5条回答
  •  失恋的感觉
    2020-12-05 00:32

    This question is a few weeks old so you may have already found the answer. This feature was added in February: https://github.com/driftyco/ionic/issues/5475.

    Taking the code from your original tab page, let's say a parameter is passed to the "parent" tab page and we want to store it in a property called fooId (this could be an object, or just a simple integer or string value, whatever):

    @Component({
        templateUrl: 'tabs.html'
    })
    export class TabsPage {
      constructor(params: NavParams) {
    
          this.params = params;
          console.log(this.params); // returns NavParams {data: Object}
          this.fooId = this.params.data;
    
          // this tells the tabs component which Pages should be each tab's root Page
          this.tab1Root = Tab1;
          this.tab2Root = Tab2;
          this.tab3Root = Tab3;
        }
    }
    

    Then in your tabs.html, you can reference it like this using the rootParams attribute (rootParams is referenced in the documenation here):

    
        
        
        
    
    

    Then in your Tab1 page, you can reference your NavParams just like any other page and the value passed for foodId will be there.

提交回复
热议问题