User avatar in sidemenu after login


#1

Hi,
I am trying to set user avatar (url to image) after user login in sidemenu. All data are store in localstorage after login - included avatar url.

But I am not able to change variable for avatar url in App component from Welcome component after login to change the image…

What is the best practice for this please?

Thanks a lot


#2

@mcihak,

Publish an event after user logged in and consume the same app.component.ts.
Login Page:
import { Events } from ‘ionic-angular’;
add public events: Events in your constructor.
add this.events.publish(‘userloggedin’); in your login process
in your app.component.ts
import { Nav, Platform,Events } from ‘ionic-angular’;
add public events: Events in your constructor. add below constructor

// this event subscribe is used to load dynamic menu
this.events.subscribe(‘userloggedin’,(() => {console.log(‘event received’);
this.getMenuOptions(); }));
}


#3

Can I ask, what you have it function getMenuOptions()?


#4

In my case, Side menu options are dynamic from server, based on logged in user role