I am trying to setup a confirmation dialog on an ng-click using a custom angularjs directive:
app.directive(\'ngConfirmClick\', [
function()
For me, https://www.w3schools.com/js/js_popup.asp, the default confirmation dialog box of the browser worked a great deal. just tried out this:
$scope.delete = function() {
if (confirm("sure to delete")) {
// todo code for deletion
}
};
Simple.. :)
But I think you can't customize it. It will appear with "Cancel" or "Ok" button.
EDIT:
In case you are using ionic framework, you need to use the ionicPopup dialog as in:
// A confirm dialog
$scope.showConfirm = function() {
var confirmPopup = $ionicPopup.confirm({
title: 'Delete',
template: 'Are you sure you want to delete this item?'
});
confirmPopup.then(function(res) {
if(res) {
// Code to be executed on pressing ok or positive response
// Something like remove item from list
} else {
// Code to be executed on pressing cancel or negative response
}
});
};
For more details, refer: $ionicPopup