RSA
RSA

Reputation: 1449

Navparam passed data are not available in Ionic2

In login page application will get UDI and Token and if login/registration is successful it will pass to MapPage:

if (Token != "-1")
                   {                  
                this.navCtrl.push(MapPage, {UDI: this.UDI, Token: Token})
                this.navCtrl.setRoot(MapPage);
                this.navCtrl.popToRoot;

in construct method before popToRoot firesconsole.log(this.UDI, this.Token); shows the value of them but after that they are undefined.

this.UDI=this.params.get('UDI');
this.Token=this.params.get('Token');    
console.log(this.UDI, this.Token);

update 1: the result enter image description here

as you can see before going to map page it shows the right passed values

map.ts:39 2NYIRWI0N8Z6HW2M3HWR XWRU441NHH0B9GSHVC3P

but after navigation root page changing

map.ts:39 undefined undefined

Upvotes: 2

Views: 342

Answers (2)

sebaferreras
sebaferreras

Reputation: 44659

because map page is main page and there shouldn't be back button.

Just like @suraj says, you're pushing the view with parameters, and then setting the same page as root but without parameters. That's not correct. If you don't want to show the back arrow, just set the page as root

if (Token != "-1") {                  
    // this.navCtrl. push(MapPage, {UDI: this.UDI, Token: Token}) <- don't do that
    this.navCtrl.setRoot(MapPage, {UDI: this.UDI, Token: Token}); <- send the data like this
    // this.navCtrl.popToRoot; <- don't do that
    // ...
}

Upvotes: 1

Suraj Rao
Suraj Rao

Reputation: 29614

Your keys look like variables rather than string literals.So your key and value are both values of UDI and Token.

Try with quotes.

        this.navCtrl.setRoot(MapPage, {'UDI': this.UDI, 'Token': Token})

Also you are doing both push with params and then setRoot without params. Your map page is set as root without params. setRoot function also takes params

Upvotes: 1

Related Questions