Reputation: 40
My code is taking data from another controller like this:
In the function that i send the info from the controller 1 is
setAhorcado(){ this.navCtrl.push(AhorcadoPage,{itemMsg:this.itemMsg}) }
And in the other i receive normally and set the variable
itemMsg: any;
And in the constructor
this.itemMsg = this.navParams.get('itemMsg');
And... when i did a console.log the variable (in ionViewDidLoad()) is printed two times from the same line and the first time says undefined, and after that is the object.
Can you help me guys? Another problem is when i receive the object and i need an attribute like
this.nombres = this.itemMsg.pass[0].value
console.log(this.nombres.length());
Cannot read the length
Check it:
The code when i receive the object from the 2nd controller is:
@IonicPage()
@Component({
selector: 'page-ahorcado',
templateUrl: 'ahorcado.html',
})
export class AhorcadoPage {
itemMsg: any = this.itemMsg;
letra: string = '';
nombres: any = ['ferrocarril'];
nombreSecreto: any = this.palabraAleatoria(0, (this.nombres.length - 1));
palabra: any = '';
muestraHuecos: any = this.muestraHuecosPalabra();
mensaje: string = '';
letras_utilizadas: string = '';
nombresecretomostrar: string = '';
vidas: number = 6;
ganador: number = 0;
imagen: number = 1;
durationMessages: number = 3000;
// Creamos un array para guardar las letras que se van seleccionando.
controlLetras = new Array;
private callback: Function;
constructor(public navCtrl: NavController, public navParams: NavParams, private toastCtrl: ToastController,
public alertCtrl: AlertController) {
this.itemMsg = this.navParams.get('itemMsg');
console.log(this.itemMsg);
}
And in the first is the push:
setAhorcado(){
this.navCtrl.setRoot(AhorcadoPage);
this.navCtrl.push(AhorcadoPage,{itemMsg:this.itemMsg})
}
Upvotes: 0
Views: 108
Reputation: 3404
this is happening because your are using navCtrl 2 times.
setAhorcado(){
this.navCtrl.setRoot(AhorcadoPage);
this.navCtrl.push(AhorcadoPage,{itemMsg:this.itemMsg})
}
either you use:
setAhorcado(){
this.navCtrl.setRoot(AhorcadoPage,{itemMsg:this.itemMsg});
}
or this:
setAhorcado(){
this.navCtrl.push(AhorcadoPage,{itemMsg:this.itemMsg})
}
Your are using navCtrl 2 time with setRoot()
and push()
.
use any one of them.
Upvotes: 1