admin管理员组文章数量:1278910
In angularjs I want to show confirm dialog on delete operation my code is below :
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 ' +
'<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
}
}
But dialog is displayed after whole function execution, so in if condition result variable get undefined value
In angularjs I want to show confirm dialog on delete operation my code is below :
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 ' +
'<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
}
}
But dialog is displayed after whole function execution, so in if condition result variable get undefined value
Share Improve this question asked May 11, 2015 at 11:45 ShoaibShoaib 8521 gold badge15 silver badges28 bronze badges 2-
You should execute the part
perform delete operation
inside thethen
callback where you setresult=true
. You could also call a function from there that performs the delete. This is the right place to do it – devnull69 Commented May 11, 2015 at 11:49 - yes, you are right performing delete operation inside then callback works, thanks – Shoaib Commented May 11, 2015 at 11:58
1 Answer
Reset to default 10Callback are asynchronous. So, you have to perform your operation in your success callback like this:
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 ' +
'<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 - In angularjs ngDialog.openConfirm dialog appears after whole function execution - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741233956a2362635.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论