如何根据条件显示多个菜单

时间:2017-02-20 15:37:14

标签: ionic2

我是离子2的初学者

以下是我的HTML代码,用于启用使用离子框架的侧边菜单

<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>

这是我的应用程序组件

  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。 我需要显示另一个基于用户条件的菜单

请告诉我, 谢谢&amp;此致

1 个答案:

答案 0 :(得分:0)

您可以为菜单指定ID,并根据您的情况启用或禁用菜单。 https://github.com/driftyco/ionic/tree/master/demos/src/menu

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