-1

Can anyone give me a working example of how to use toggle promise in ionic using angular.

toggle(animated?: boolean) => Promise<boolean>

I want to call a user define function on menu close.How to use this the above toggle.I have seen this but that doesn't answer my question

midhunsivarajan
  • 49
  • 1
  • 11

2 Answers2

1

In your app.html file

<ion-menu side="start" menuId="first" contentId="main" (ionDidClose)="menuClosed()">

And then in your app.ts file you write your event handler functions

menuClosed() {
      //code to execute when menu has closed
}

PS: ionDidClose is Emitted when the menu is closed.

Franky
  • 902
  • 2
  • 11
  • 28
1

If the method returns a Promise with boolean, you need to call your own method after such Promise gets resolved:

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) { }

  myCustomMethod() {
    // your custom method logic
  }

  openCustom() {
    this.menu.toggle(true).then((toggled) => {
        if (toggled) {
            this.myCustomMethod()
        }
    })
  }
}
Sergey Rudenko
  • 8,809
  • 2
  • 24
  • 51