Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 3: Passing Data when Setting the root page

I am checking some localstorage info and depending on the info I get I want to load the appropriate page.

So in my app.component.ts I have the following.

export class MyApp {
  rootPage: string;

 constructor(){
  if(dataFound)
   this.rootPage="HomePage"
  else
   this.rootPage="OtherPage"
  }
}

Is there a way I can pass data when setting the this.rootPage.

Keep in mind that this is the initial load of the app. If this happen after the app has loaded I can do this.navCtrl.setRoot() which will allow me to pass parameters along with the page.

Any help is appreciated.

Thanks

like image 832
krv Avatar asked Dec 10 '22 08:12

krv


1 Answers

As @gaborp said, but with a little difference :

  1. In your root:

    <ion-nav [root]="rootPage" [rootParams]="rootPageParams"></ion-nav>

    this.rootPageParams = {'username': "David" }

  2. In the view you want to read that param (this is the difference):

    this.username = this.nav['rootParams'].username;

All I read was about tabs, but nothing for a simple ion-nav, so that is the way I did it.

like image 79
Duveral Avatar answered Dec 29 '22 00:12

Duveral