gpt4 book ai didi

javascript - 在 angularjs ngDialog.openConfirm 对话框出现在整个函数执行后

转载 作者:搜寻专家 更新时间:2023-11-01 05:04:42 25 4
gpt4 key购买 nike

在 angularjs 中,我想显示删除操作的确认对话框,我的代码如下:

function deleteOperation(){
var result;
ngDialog.openConfirm({
template:
'<p>Are you sure you want to delete selected conversation(s) ?</p>' +
'<div>' +
'<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No&nbsp;' +
'<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' +
'</button></div>',
plain: true,
className: 'ngdialog-theme-default'
}).then(function (value) {
result=true;
}, function (value) {
result=false;
});

if (result == true) {
// perform delete operation
}
}

但是对话框是在整个函数执行完之后才显示的,所以在if条件结果变量得到未定义的值

最佳答案

回调是异步的。因此,您必须像这样在成功回调中执行您的操作:

function deleteOperation(){     
ngDialog.openConfirm({
template:
'<p>Are you sure you want to delete selected conversation(s) ?</p>' +
'<div>' +
'<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No&nbsp;' +
'<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' +
'</button></div>',
plain: true,
className: 'ngdialog-theme-default'
}).then(function (value) {
// perform delete operation
}, function (value) {
//Do something
});
}

关于javascript - 在 angularjs ngDialog.openConfirm 对话框出现在整个函数执行后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30166836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com