Ionic 3, "push" of variables

Asked

Viewed 325 times

0

Good afternoon guys, could someone help me with this basic question ? how do I take the variable from a ts file and throw it into another file ? example... in one 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 also !!! How would it be possible ? Thank you already !!!

  • but you want to pass the value and change the page right?

1 answer

0


I understand that you want to go from a page A to a page B and take values from A to B. If so, use the 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 its Page B

import { NavParams } from 'ionic-angular';

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

From a look at documentation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.