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
Callback 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
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With