使用Angular在Ionic 5中打开离子菜单时隐藏任何div或文本

问题描述 投票:0回答:2

我想在打开离子性侧面菜单时隐藏工具栏.custom-nav-link div,并在关闭侧面菜单时再次显示此工具。如何检测和应用基于离子菜单的HTML条件是打开还是关闭?

enter image description here

<ion-toolbar>
  <div class="containers">
    <div class="logo" >
      <h4>My Toolbar</h4>
    </div>

    <div class="custom-nav-link" slot="end">
      <nav class="desktop-nav">
        <ul class="nav-list">
          <li *ngFor="let p of buttonLinks">
            <a href="">{{p.title}}</a>
          </li>
        </ul>
      </nav>
    </div>

    <div class="">
      <ion-buttons slot="start">
        <ion-menu-button menu="userMenu">
          <ion-icon name="apps"></ion-icon>
        </ion-menu-button>
      </ion-buttons>
    </div>

  </div>
</ion-toolbar>
angular ionic-framework ionic4 ionic-native
2个回答
0
投票

您可以为此使用MenuController

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

constructor(public menuCtrl:MenuController){}

HTML中

<ion-toolbar>
  <div class="containers">
    <div class="logo" >
      <h4>My Toolbar</h4>
    </div>

    <div *ngIf="!menuCtrl.isOpen('menuId')" class="custom-nav-link" slot="end">
      <nav class="desktop-nav">
        <ul class="nav-list">
          <li *ngFor="let p of buttonLinks">
            <a href="">{{p.title}}</a>
          </li>
        </ul>
      </nav>
    </div>

    <div class="">
      <ion-buttons slot="start">
        <ion-menu-button menu="userMenu">
          <ion-icon name="apps"></ion-icon>
        </ion-menu-button>
      </ion-buttons>
    </div>

  </div>
</ion-toolbar>

0
投票

尝试一下:

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

public isMenuOpen: boolean = false;

constructor(public menuCtrl:MenuController){}

ngOnInit() {   // or on click of menu button
    this.menuCtrl.isOpen('userMenu').then(res => {
        this.isMenuOpen = res;
    })
}

和html

<div *ngIf="!isMenuOpen" class="custom-nav-link" slot="end">
  <nav class="desktop-nav">
    <ul class="nav-list">
      <li *ngFor="let p of buttonLinks">
        <a href="">{{p.title}}</a>
      </li>
    </ul>
  </nav>
</div>

<div class="">
  <ion-buttons slot="start">
    <ion-menu-button menu="userMenu">
      <ion-icon name="apps"></ion-icon>
    </ion-menu-button>
  </ion-buttons>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.