Lo que intento hacer es que al iniciar sesión en mi app, el sidemenu se actualice y me aparezcan las opciones correspondientes según el tipo de usuario que inicio sesión.
El método para iniciar sesión es el siguiente:
login() {
this.Loading("","send");
this.http.postData(this.userData, "post/login").subscribe( result => {
this.responseData = result;
if (this.responseData.success) {
localStorage.setItem('userSesion', JSON.stringify(this.responseData.dataUser));
if (this.responseData.dataUser.tipo === '1') {
this.navCtrl.setRoot(InicioPage);
} else if (this.responseData.dataUser.tipo === '2') {
this.navCtrl.setRoot(IniciodocentePage);
}
} else {
this.Loading(this.responseData.dataUser,"error");
}
}, (err) => {
console.log(err);
});
}
En mi app.component.ts en donde están los arreglos con las opciones del menú esta de la siguiente manera:
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any = HomePage;
pages: Array<{title: string, component: any}>;
public sesion:boolean;
public opt:boolean;
userDetails:any = {};
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen) {
this.initializeApp();
if (localStorage.getItem('userSesion')) {
const data = JSON.parse(localStorage.getItem('userSesion'));
this.userDetails = data;
this.sesion = true;
if (this.userDetails.tipo == '1') {
this.pages = [
{ title: 'Inicio', component: InicioPage },
{ title: 'Registro de Inscripción', component: CarrerasestudiantePage },
{ title: 'Historial Academico', component: HistoricoPage },
{ title: 'Procesar Inscripción', component: ProcesarinscripcionPage }
];
} else if (this.userDetails.tipo == '2') {
this.pages = [
{ title: 'Inicio', component: IniciodocentePage },
{ title: 'Mi Carga Académica', component: CargaacademicaprofesorPage }
];
}
} else {
this.pages = [
{ title: 'Entrar', component: HomePage },
{ title: 'Olvide mi clave', component: AboutPage },
{ title: 'Consultar Estatus', component: ContactPage }
];
this.sesion = false;
}
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
openPage(page) {
this.nav.setRoot(page.component);
}
}
El problema es que cuando inicio sesión me siguen apareciendo las opciones en el menú que tengo antes de iniciar sesión. Si presiono F5 ahí si se recarga el sidemenu y me aparecen las opciones correspondientes según el tipo de usuario.