I've put an example directive in:
http://plnkr.co/edit/GJwK7ldGa9LY90bMuOfl?p=preview
I achieve it by creating a directive:
- with a higher
priority
than ngClick
, so that it gets called before ngClick
,
- making that
terminal
so that it doesn't call ngClick
.
- listening to click events, and then evaluating the
ngClick
value if the message is ok.
As a bonus, you can pass in your own message, such as:
<a href="#" ng-click="deleteIt(id)"
confirmation-needed="Really Delete?"
>Delete with custom message</a>
The code looks like this:
app.directive('confirmationNeeded', function () {
return {
priority: 1,
terminal: true,
link: function (scope, element, attr) {
var msg = attr.confirmationNeeded || "Are you sure?";
var clickAction = attr.ngClick;
element.bind('click',function () {
if ( window.confirm(msg) ) {
scope.$eval(clickAction)
}
});
}
};
});
Hope that helps.