2017-02-20 70 views
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的有条件的另一个菜单

请咨询我, 感谢&问候

回答

0

您可以将菜单给ID并启用或禁用根据你的病情菜单。 https://github.com/driftyco/ionic/tree/master/demos/src/menu

menu.enable(true/false, #menu);

+0

感谢乌尔Reply.I在所谓的新funtion isUserLoggedIn()后,无法安慰的价值。是我的功能检查(){ VAR AUTH = localStorage.getItem( '电子邮件' ); if(auth!= null) { this.authservice.checkRole(); } } –

+0

尝试window.localStorage.getItem('email'),甚至检查undefined以及null(auth!='undefined')。 – Naveen

+0

我称这个函数为constructor.Check以下条件:ion-list * ngIf =“currentuser ==='6'”> 不能DISPLY菜单,但我的角色ID也是‘6’ –