硬件返回按钮被调用两次ionic5



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


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

但是当我点击按钮时,它被调用了两次。我用的是ionic5。什么好主意吗?

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

最新更新