I am trying to setup a confirmation dialog on an ng-click using a custom angularjs directive:
app.directive(\'ngConfirmClick\', [
function()
Here is a clean and simple solution using angular promises $q, $window and native .confirm() modal:
angular.module('myApp',[])
.controller('classicController', ( $q, $window ) => {
this.deleteStuff = ( id ) => {
$q.when($window.confirm('Are you sure ?'))
.then(( confirm ) => {
if ( confirm ) {
// delete stuff
}
});
};
});
Here I'm using controllerAs syntax and ES6 arrow functions but it's also working in plain ol' ES5.