How to pass a parameter(logged user) to all the ionic pages

#1

I want to pass user name to all the pages… Please help me

#2

Hi @Velmurugan,

You can create a service to store the username and other data there, and access to it from the pages that need it. Check out this tutorial on services: https://www.joshmorony.com/when-to-use-providersservicesinjectables-in-ionic/

Best,
Rodrigo

#3

Thanks… Romerio…

#4

No problem! By the way, my name is Rodrigo :sweat_smile:

1 Like
#5

one small doubt. Suppose if i am not using the server side code , how i will send my logged user_name to my provider .

this is the code i have seen in provider,
getUsers(){

    return this.http.get('https://someserver.com/api/users').map(res => res.json());

}

In my case , 
1.First time the login screen will open  with otp. then go to Home page..

2.Second time directly go to home page

login.ts

 this.navCtrl.push(SignupPage,{logged_user:phoneNumber});

home.ts 

constructor (){
this.logged_user = this.navParams.get('logged_user');           // second time this will return null
}

  public async get_user() {
    if (logged_user !== undefined) {
      console.log('User is already set.');
    }
    this.logged_user = await this.storage.get('username');  //second time will get the data from here

    console.log(this.logged_user, ' is already  loggedin home screen ');
    this.checkUsername(this.logged_user);
  }