Create a confirmation alert for delete button in Angular using JS

angularjs, confirmation, javascript

Solution

Seems like an AngularJS directive is a bit over-the-top for a solution to this. Seems easier just to use straight javascript unless you need some custom functionality to your "confirm()" function.

if (confirm('Are you sure you want to delete this?')) {
     // TODO:  Do something here if the answer is "Ok".
}

Hope this helps, cheers

UPDATE: Actually, with Angular, it would be better to use $window.confirm as this would allow you to test with Karma/Jasmine.

Problem

I have a form that has a delete button, I would like to create a confirmation box that pop ups when the delete button is clicked. The delete button currently works. I have tried several things in javascript with no luck. I am using Angular. Is this best approach for this? Also, does anyone know of any examples for this, I have not found any that work. ``` $(document).ready(function(){ $("form").validate(); $(".radius small success button").ConfirmDialog('Are you sure?'); }); ```

Original source