我想在打开离子性侧面菜单时隐藏工具栏.custom-nav-link
div,并在关闭侧面菜单时再次显示此工具。如何检测和应用基于离子菜单的HTML条件是打开还是关闭?
<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>
您可以为此使用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>
尝试一下:
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>