0
我多個菜單初學者到離子2如何根據條件顯示
下面是其中正在使用,使側面菜單使用離子框架
<ion-content>
<ion-list *ngIf="!isUserLoggedIn()">
<button menuClose ion-item *ngFor="let p of loginPages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
<ion-list *ngIf="isUserLoggedIn()">
<button menuClose ion-item *ngFor="let p of logoutpages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
</ion-content>
我的HTML代碼,這是我的應用程序組件
currentuser;
@ViewChild(Nav) nav: Nav;
auth:any;
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 }
];
isUserLoggedIn(): boolean {
let user = this.authservice.getcurrentuser();
return user !== null;
}
已經顯示基於isUserLoggedIn的logoutpages。 我需要顯示基於UserRole的有條件的另一個菜單
請諮詢我, 感謝&問候
感謝烏爾Reply.I在所謂的新funtion isUserLoggedIn()後,無法安慰的價值。是我的功能檢查(){ VAR AUTH = localStorage.getItem( '電子郵件' ); if(auth!= null) { this.authservice.checkRole(); } } –
嘗試window.localStorage.getItem('email'),甚至檢查undefined以及null(auth!='undefined')。 – Naveen
我稱這個函數爲constructor.Check以下條件:ion-list * ngIf =「currentuser ==='6'」> 不能DISPLY菜單,但我的角色ID也是‘6’ –