Last active
August 29, 2015 14:14
-
-
Save lutsen/c764fa9207783d0153e2 to your computer and use it in GitHub Desktop.
An Angular directive to show a javascipt confirmation message when the user clicks a page element. The ng-confirm-click attribute contains the text in the confirmation window. The confirmed-click attribute contains the actual ation that is executed if the user confirms.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/18313576/confirmation-dialog-on-ng-click-angularjs | |
// http://plnkr.co/edit/YWr6o2?p=preview | |
angular.module('yourApp') | |
.directive('ngConfirmClick', function () { | |
return { | |
link: function (scope, element, attr) { | |
var msg = attr.ngConfirmClick || "Are you sure?"; | |
var clickAction = attr.confirmedClick; | |
element.bind('click',function (event) { | |
if ( window.confirm(msg) ) { | |
scope.$apply(clickAction) | |
} | |
}); | |
} | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button confirmed-click="delete($index, '{{object.id}}')" ng-confirm-click="Are you sure you want to delete {{object.name}}?"> | |
Delete | |
</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment