Hi ,
I am beginner to ionic 2
This is my app component
currentuser;
@ViewChild(Nav) nav: Nav;
auth: any;
menu;
rootPage: any = LoginPage;
loginPages: PageInterface[] = [
{ title: 'Login', component: LoginPage }
];
logoutpages: PageInterface[] = [
{ title: 'My Complaints', component: MycomplaintsPage },
{ title: 'My Neighbours', component: NeighboursPage },
{ title: 'Notifications', component: NotificationsPage },
{ title: 'Directory', component: TabsPage },
{ title: 'chat', component: ChatlistPage },
{ title: 'Events', component: EventPage },
{ title: 'settings', component: SettingsPage },
{ title: 'LogOut', component: LoginPage, logsOut: true }
];
userrole: PageInterface[] = [
{ title: 'Property', component: PropertyPage },
{ title: 'settings', component: SettingsPage },
{ title: 'LogOut', component: LoginPage, logsOut: true }
]
constructor(public menu1: MenuController, public alertCtrl:AlertController, public platform: Platform, public authservice:Authservice) {
this.auth = localStorage.getItem("email");
console.log("Auth" + this.auth);
this.initializeApp();
if (this.auth != null) {
this.authservice.checkRole().subscribe(data => {
this.currentuser = data[0].ROLE_ID;
console.log(this.currentuser)
console.log(typeof (this.currentuser));
})
}
}
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Splashscreen.hide();
console.log(Network.type);
if (Network.type === Connection.NONE) {
console.log("success");
let alert = this.alertCtrl.create({
title: "Internet Connection",
subTitle: "Please Check Your Network connection",
buttons: [
{
text: 'Ok',
handler: () => {
this.platform.exitApp();
}
}
]
});
alert.present();
}
});
}
openPage(page) {
// Reset the content nav to have just this page
// we wouldn't want the back button to show in this scenario
// this.authservice.getLoggedInUser();
this.nav.setRoot(page.component);
if (page.logsOut === true) {
localStorage.clear();
this.authservice.logout();
}
}
isUserLoggedIn():boolean {
let user = this.authservice.getcurrentuser();
console.log(user);
return user !== null;
}
watchForNetworkChanges() {
// Watch network for a connection
let disconnectSub = Network.onDisconnect().subscribe(() => {
console.log('you are offline');
});
let connectSub = Network.onConnect().subscribe(() => {
console.log('you are online');
});
}
already i display logoutpages based on isUserLoggedIn. I need display another menu based on userrole with session conditions
Example Manager login can view the all menu list.
Normal user login another set of menu pages
I dont have any idea
also i refer this link
Kindly advice me,
Thanks & Regards