Ionic 3, "push" of variables

0

Good afternoon, could anyone help me with this basic question? how do I get the variable from a ts file and throw it in another file? example... in one of the typescript I have a variable that receives the value given through this function ... I wanted that after this variable received the value, it went to another page .ts too !!! How could it be? Thank you in advance !!!

    
asked by anonymous 25.07.2018 / 22:26

1 answer

0

I understand that you want to go from page A to page B and take values from A to B. If so, use NavController and NavParams .

Example:

import { NavController } from 'ionic-angular';
import { PaginaB } from 'caminho/para/seu/component/PaginaB';
export class PaginaA {
  private variavel: string = "Valor a ser passado para PaginaB";
  constructor(public navCtrl: NavController) {}

  private irParaPaginaB(){
    this.navCtrl.push(PaginaB, {parametro: this.variavel})
  }
}

On your Page B

import { NavParams } from 'ionic-angular';

export class PaginaB{
  private variavel: string;
  constructor(private navParams: NavParams) {
     this.variavel = navParams.get('parametro');
  }
}

Take a look at the documentation

    
08.08.2018 / 00:19