离子:单击“确定”时防止警报自动关闭

Meh*_*way 2 ionic-framework

单击“确定”会自动解除警报。我想在“确定”点击处理程序中添加一些逻辑,然后决定是否要解除警报。

let inputsAlert = this.alertCtrl.create({
    ...
    buttons: [
        {
            text: 'OK',
            handler: inputsData => {

                // Some logic here

                if (canDismiss) {
                    this.inputsAlert.dismiss();
                } else {
                    // Do nothing
                }
            }
        }
    ]
})
Run Code Online (Sandbox Code Playgroud)

Wei*_*Tan 7

在按钮数组中,每个按钮都包含其文本的属性,以及可选的处理程序。如果处理程序返回 false,则单击按钮时不会自动解除警报。

来自https://ionicframework.com/docs/api/alert#buttons

很简单,return false如果您不想解除警报。

  • 仅当处理函数未声明为“async”时才有效。 (2认同)