NavParams: undefined parameter caused by double (automatic?) load of a page


#1

Hi to everyone,
i’m trying to send a parameter from a first component to a second component in this way (only relevant code of first component, if i try this.navCtrl.setRoot etc i get the same effect):

this.navCtrl.push(SecondComponent,{infodata: "val" });

In my second component (only relevant code):

datarec;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.datarec=this.navParams.get('infodata');
console.log(this.datarec);
}

in my console i can see:
val
undefined

So this code is called two times and the problem is that i can’t use my parameter because it’s always undefined. My questions:
Why it’s called two times? What can make reload the page of the second component?
thanks who will try to help.


#2

That isn’t the only relevant code if you’re getting that behavior. What you posted should work.


#3

Can you give me some advice of what can make my second component to reload a second time?
I can say this: i’m sure that this second component is only called by my first component inside the app.

It’s not normal that a component is loaded two times right?


#4

You could make a github repo and ask someone to check it, or post more code here. You’re probably doing something “obvious” that isn’t obvious because it takes experience to keep track of all the details.