【问题标题】:How to call the menu toggle promise in ionic framework如何在离子框架中调用菜单切换承诺
【发布时间】:2020-02-12 22:50:04
【问题描述】:

谁能给我一个工作示例,说明如何使用 angular 在离子中使用切换承诺。

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

我想在菜单关闭时调用用户定义函数。如何使用上面的切换。我有 seen this 但这不能回答我的问题

【问题讨论】:

    标签: angular typescript ionic-framework


    【解决方案1】:

    如果该方法返回一个带有布尔值的 Promise,则需要在此类 Promise 解决后调用自己的方法:

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

    【讨论】:

      【解决方案2】:

      在您的 app.html 文件中

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

      然后在 app.ts 文件中编写事件处理函数

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

      PS:关闭菜单时会发出 ionDidClose。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-05
        • 1970-01-01
        • 2018-05-04
        • 2016-03-27
        • 1970-01-01
        • 2021-03-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多