【问题标题】:Ionic : Prevent alert auto dismiss when clicked on 'OK'离子:单击“确定”时防止警报自动关闭
【发布时间】:2019-08-25 11:01:13
【问题描述】:

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

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

                // Some logic here

                if (canDismiss) {
                    this.inputsAlert.dismiss();
                } else {
                    // Do nothing
                }
            }
        }
    ]
})

【问题讨论】:

    标签: ionic-framework


    【解决方案1】:

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

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

    如果您不想解除警报,只需 return false

    【讨论】:

    • 仅在处理函数未声明为async时有效。
    • @user1364368 使用thenables 而不是async/await
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    • 2011-08-08
    • 2018-03-14
    • 2016-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多