0

我的应用程序有两种用户类型客户和员工,对于他们每个人,我需要不同的菜单。如何在 app.component.html 页面中添加一些条件,例如 this.usertype = "Staff" 使用员工菜单,否则使用客户菜单。我尝试使用不同的 ID,但在这种方法中,第一个菜单似乎消失了。希望你能帮我!提前致谢!

我在 app.component.html 中的当前代码

<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@200;300&display=swap" rel="stylesheet">
<ion-app>
  <ion-menu menuId="main-menu" side="start" content-id="main-content">
    <ion-header>
      <ion-toolbar translucent>
        <ion-title style="font-family: 'Poppins';font-weight: 300;">Menu</ion-title>
      </ion-toolbar>
    </ion-header>
    <ion-content>
      <ion-list>
        <ion-item routerLink="/homepagee">
          <ion-label style="font-family: 'Poppins'">Home</ion-label>
        </ion-item>
        <ion-item routerLink="/terms">
          <ion-label style="font-family: 'Poppins'">Terms & Conditions</ion-label>
        </ion-item>
        <ion-item routerLink="/privacy">
          <ion-label style="font-family: 'Poppins'">Privacy Policy</ion-label>
        </ion-item>
        <ion-item routerLink="/myaccount">
          <ion-label style="font-family: 'Poppins'">My Details</ion-label>
        </ion-item>
        <ion-item routerLink="/home">
          <ion-label style="font-family: 'Poppins'">Logout</ion-label>
        </ion-item>
      </ion-list>
    </ion-content>
  </ion-menu>


  <ion-menu menuId="main-menu2" side="start" content-id="main-content2">
    <ion-header>
      <ion-toolbar translucent>
        <ion-title style="font-family: 'Poppins';font-weight: 300;">Menu</ion-title>
      </ion-toolbar>
    </ion-header>
    <ion-content>
      <ion-list>
        <ion-item routerLink="/homepagee">
          <ion-label style="font-family: 'Poppins'">Announcments</ion-label>
        </ion-item>
        <ion-item routerLink="/terms">
          <ion-label style="font-family: 'Poppins'">Terms & Conditions</ion-label>
        </ion-item>
        <ion-item routerLink="/privacy">
          <ion-label style="font-family: 'Poppins'">Privacy Policy</ion-label>
        </ion-item>
        <ion-item routerLink="/myaccount">
          <ion-label style="font-family: 'Poppins'">Chat</ion-label>
        </ion-item>
        <ion-item routerLink="/home">
          <ion-label style="font-family: 'Poppins'">Logout</ion-label>
        </ion-item>
      </ion-list>
    </ion-content>
  </ion-menu>

  <ion-router-outlet id="main-content"></ion-router-outlet>
  <ion-router-outlet id="main-content2"></ion-router-outlet>
</ion-app>
4

1 回答 1

0

对于这种情况,请使用MenuController示例:

import { Component } from '@angular/core';
import { MenuController } from '@ionic/angular';

@Component({
  selector: 'menu-example',
  templateUrl: 'menu-example.html',
  styleUrls: ['./menu-example.css'],
})
export class MenuExample {

 constructor(private menu: MenuController) { 

   if(this.usertype = "Staff" ){
    this.menu.enable(true, 'Your_Staff_MenuID'); 
   }else{
    this.menu.enable(true, 'Your_Other__MenuID'); 
   }
 }   

}
于 2021-03-20T06:08:51.860 回答