Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if side menu is open/closed in ionic 2?

I am using cordova-google-maps plugin with my ionic 2 app, and I want to show the menu (sidenav) on that page. Problem is for the sidenav to receive events properly I need to call map.setClickable( false ) while opening the sidenav and set it back to true when the user closes the sidenav. It seems there is an event for checking while the menu is being opened with opening, but I don't know how to track when the user closes the menu.

like image 321
btDev Avatar asked May 13 '16 16:05

btDev


1 Answers

For using ionDrag, ionOpen, ionClose in Ionic2 you must add it on the menu itself

for example modify menu in your app.html file by

<ion-menu [content]="content" (ionOpen)="menuOpened()" (ionClose)="menuClosed()">

After I use "Events" see doc here: http://ionicframework.com/docs/v2/api/util/Events/

For detect in my page if the menu was close or open.

Example in my app.ts

menuClosed() {
    this.events.publish('menu:closed', '');
}

menuOpened() {
    this.events.publish('menu:opened', '');
}

And in my other page

events.subscribe('menu:opened', () => {
    // your action here
});

events.subscribe('menu:closed', () => {
    // your action here
});

I hope this help

like image 185
Ludovic Avatar answered Sep 17 '22 02:09

Ludovic