Prevent multiple Ionic Alerts from stacking up

前端 未结 4 1213
孤城傲影
孤城傲影 2021-02-20 06:37

How can I detect if ionic 2 alert ui component instance is already open in order not to present another alert ?

4条回答
  •  無奈伤痛
    2021-02-20 07:31

    My solution worked, i had to put a boolean and set it true after a cancel event and set it false when an alert is presented

    if (this.network_alert) {
          let alert = await this.alertController.create({
            header: "No Network",
            message:
              "Please check your internet connection",
            buttons: [{
              text: "Dismiss",
              role: 'cancel',
              handler: () => {
                console.log('Cancel clicked');
                this.network_alert = true
              }
            }],
    
          });
          await alert.present();
          this.network_alert = false
        }
      }
    

提交回复
热议问题