【问题标题】:hardware back button is called twice ionic5硬件后退按钮被调用两次 ionic 5
【发布时间】:2021-12-02 23:24:07
【问题描述】:

我尝试配置硬件后退按钮并在其中调用一个函数:


import { Platform } from '@ionic/angular';
constructor(private platform: Platform) {
  this.platform.backButton.subscribeWithPriority(10, () => {
    //call my function here
  });
}

但是当我单击该按钮时,它会被调用两次。我正在使用 ionic5。 有什么想法吗?

【问题讨论】:

    标签: android angular ionic-framework mobile ionic5


    【解决方案1】:
    You can try async and await as follow
    
    import { Platform } from '@ionic/angular';
        constructor(private platform: Platform) {
          this.platform.backButton.subscribeWithPriority(10, async () => {
            await this.functionCall() // Your function call goes here
          });
        }
    

    【讨论】:

    • 感谢您的帮助,但按钮仍然执行了两次。
    猜你喜欢
    • 1970-01-01
    • 2021-10-15
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-01
    • 2020-01-28
    • 2019-01-13
    • 2019-08-11
    相关资源
    最近更新 更多