I played with this for a long time, but the async nature of Angular makes it tough to count on every directive playing nicely together. Then, I saw @tosh's answer, which got me thinking.
I think this combines several advantages: Create a Directive and Prepend ngClick
So, just add this directive to your app, and then add the "confirm-click" attribute to your link, as well as the confirmClick() function to your ngClick.
Link:
<a href="#" ng-click="confirmClick() && deleteIt(id)" confirm-click>Delete</a>
Directive:
.directive('confirmClick', function() {
return {
link: function (scope, element, attrs) {
// setup a confirmation action on the scope
scope.confirmClick = function(msg) {
// msg can be passed directly to confirmClick('are you sure?') in ng-click
// or through the confirm-click attribute on the <a confirm-click="Are you sure?"></a>
msg = msg || attrs.confirmClick || 'Are you sure?';
// return true/false to continue/stop the ng-click
return confirm(msg);
}
}
}
})
This is very similar to injecting the standard confirm() dialog, but because you have it in a directive, you can customize how you choose to run your confirm dialog (maybe a pretty modal, instead of a window dialog).
**** BONUS ANSWER ****
I played with this more and integrated a solution that uses a modal window as the confirmation, rather than the default window. Here's the complete solution: https://stackoverflow.com/a/23718694/1135826