[英]Ionic (Angular) alert handler method called twice
I am using Ionic v. ^5.0.7 (Angular v. ~9.1.6 ) for my web app and I have this weird issue - when I close alert and handler method is called, it's calling itself twice in a row.我正在为我的 web 应用程序使用 Ionic v. ^5.0.7 (Angular v. ~9.1.6 ),我遇到了这个奇怪的问题 - 当我关闭警报并调用处理程序方法时,它连续两次调用自己。
I had this issue before, but somehow after some time it stopped and start behave normally, but this time, this issue is still here.我之前遇到过这个问题,但不知何故它停止并开始正常运行,但这一次,这个问题仍然存在。
Here is part of my code:这是我的代码的一部分:
async showDialog(iterable: Array<any>) {
let inputs: Array<any> = [];
for (const x of iterable) {
inputs.unshift({
name: x.title,
type: "radio",
label: x.title,
value: x,
handler: (value) => {
this.someOtherMethod(value.value);
alert.dismiss();
},
});
}
const alert = await this.alertController.create({
header: "Title",
message: "Message",
inputs: inputs,
buttons: [
{
text: "Cancel",
role: "cancel",
cssClass: "cancel-t-button",
handler: () => {},
},
{
text: "Add",
role: "ok",
cssClass: "add-t-button",
handler: () => this.someMethod(),
},
],
});
await alert.present();
}
When I close this alert by clicking on "Add" button, handler method (console.log) is called twice in a row.当我通过单击“添加”按钮关闭此警报时,处理程序方法(console.log)连续调用两次。 Do you have any idea, where the issue could be?
你有什么想法,问题可能出在哪里?
Thanks for your help.谢谢你的帮助。
I opened a issue https://github.com/ionic-team/ionic/issues/21618 and this bug is fixed in Ionic v5.2.2我打开了一个问题https://github.com/ionic-team/ionic/issues/21618并且此错误已在 Ionic v5.2.2 中修复
I fixed this by removing role
attribute from cancel button and adding role: "cancel"
to the add button.我通过从取消按钮中删除
role
属性并将role: "cancel"
添加到添加按钮来解决此问题。 It is not the best solution, but it works... I think that problem is in the Ionic Framework.这不是最好的解决方案,但它确实有效……我认为问题出在 Ionic 框架中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.