Search code examples
phpparameterstabsionic2send

Send Only Parameters from tabs to other page - Ionic2


I'm using framework ionic 2 and I need send parameters from my tabs to other page , that page is not on my tab...

I know the method " this.navCtrl.push(view,{parameters}) " but I only need send the parameters , don't want open other page , Only parameters. please help me.

In my code I need send parameter "rut".

tabs.html:

   <ion-menu [content]="content" >
    
    <ion-header>
    <ion-toolbar>
   
           <img class="avatar" src="assets/img/i2.png">
           <div class="name-user">{{nombre}} {{apellido}}</div>
           <div class="rut-user">{{rut}}</div>

 
    </ion-toolbar>
  </ion-header>

   <ion-content >
      <ion-list>
     <div class="items-menu">
    <div class="item-menu" (click)="scan()">
          <ion-icon name="md-qr-scanner"></ion-icon>
           <div class="title">Escanear Producto</div>
    </div>


    <div class="item-menu" (click)="modificarPerfil()">
       <ion-icon name="md-person"></ion-icon>
          <div class="title">Perfil</div>
    </div>
  <div class="item-menu">
      <ion-icon name="md-settings"></ion-icon>
         <div class="title">Opciones</div>
    </div>
  <div class="item-menu">
      <ion-icon name="md-information-circle"></ion-icon>
         <div class="title">Acerca De</div>
    </div>
  <div class="item-menu"  (click)="cerrarsesion()" >
    <ion-icon name="md-log-out"></ion-icon>
          <div class="title">Cerrar Sesion</div>
    </div>
</div>
     </ion-list>
   </ion-content>
  

   </ion-menu>
   <ion-nav [root]="rootPage" #content  swipeBackEnabled="true" ></ion-nav> 


<ion-tabs color="primary">
  <ion-tab [root]="tab1Root" tabTitle="Home" tabIcon="home"></ion-tab>
  <ion-tab [root]="tab2Root"  tabTitle="Carro" tabBadge="{{num}}" tabIcon="cart"  tabBadgeStyle="danger" ></ion-tab>
  <ion-tab tabTitle="Perfil" tabIcon="md-person" (ionSelect)="modificarPerfil()"></ion-tab>
</ion-tabs>


Solution

  • I am assuming you have 3 pages: tabsAll, tab1Root, tab2Root where tabsAll is the overall and whose code is shown.

    You need to send parameters from the tabs to other page. I am assuming the other page is the other tabs? You can make use of rootParams to pass parameters from tabs to other tabs.

    tabsAll html

    <ion-tabs color="primary">
      <ion-tab [root]="tab1Root" [rootParams]="{rutValue: rut}"></ion-tab>
      <ion-tab [root]="tab2Root" [rootParams]="{rutValue: rut}" ></ion-tab>
    </ion-tabs>
    

    tab1Root js

    constructor(..., private navParams : NavParams){
      var rut = navParams.get("rutValue");
    }
    

    More documentation about rootParams here: https://ionicframework.com/docs/api/components/tabs/Tab/

    Let me know if this is what you wanted.