簡體   English   中英

離子(Angular)警報處理程序方法調用了兩次

[英]Ionic (Angular) alert handler method called twice

我正在為我的 web 應用程序使用 Ionic v. ^5.0.7 (Angular v. ~9.1.6 ),我遇到了這個奇怪的問題 - 當我關閉警報並調用處理程序方法時,它連續兩次調用自己。

我之前遇到過這個問題,但不知何故它停止並開始正常運行,但這一次,這個問題仍然存在。

這是我的代碼的一部分:

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

當我通過單擊“添加”按鈕關閉此警報時,處理程序方法(console.log)連續調用兩次。 你有什么想法,問題可能出在哪里?

謝謝你的幫助。

我打開了一個問題https://github.com/ionic-team/ionic/issues/21618並且此錯誤已在 Ionic v5.2.2 中修復

我通過從取消按鈕中刪除role屬性並將role: "cancel"添加到添加按鈕來解決此問題。 這不是最好的解決方案,但它確實有效……我認為問題出在 Ionic 框架中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM