Hi,
My use case; Side menu options are based on logged In user. I built a service to get sidemenu options from server after user login.
Below is high level steps;
Login Screen:
import { Events } from ‘ionic-angular’;
constructor:
public events: Events
after authenticating login : publish an event
this.events.publish(‘userloggedin’);
app.components.ts:
import { Events } from ‘ionic-angular’;
constructor:
public events: Events
subscribe the previously published event in constructor
add below in constructor:
this.events.subscribe(‘userloggedin’,(() => {console.log(‘event received’);
this.getMenuOptions(); // this method gets sidemenu options from server }));
may be in your use case;
different sidemenu’s before and after login
have 3 arrays:
array 1
beforeloginpages= [
{ title: ‘Page1Page’, component: Page1Page},
{ title: ‘Page2Page’, component: Page2Page},
];
array 2
afterloginpages = [
{ title: ‘Page1Page’, component: Page1Page},
{ title: ‘Page3Page’, component: Page3Page},
{ title: ‘Page4Page’, component: Page4Page},
];
// activapages array would be displayed in your app.html
activepages:[]
before login
this.activepages = beforeloginpages;
afterlogin in the event
this.events.subscribe(‘userloggedin’,(() => {console.log(‘event received’);
this.activepages = afterloginpages; }));
logout: Publish an event and switch the arrays
Please let me know, if you need any additional help
Thanks,
Raj