Skip to content

Instantly share code, notes, and snippets.

@brunovianarezende
Forked from asafge/ng-really.js
Last active February 11, 2018 13:35
Show Gist options
  • Save brunovianarezende/8437155 to your computer and use it in GitHub Desktop.
Save brunovianarezende/8437155 to your computer and use it in GitHub Desktop.
ng-confirm - An AngularJS directive that creates a confirmation dialog for an action. Forked from https://gist.github.com/asafge/7430497
/**
* A generic confirmation for risky actions.
* Usage: Add attributes:
* * ng-confirm-message="Are you sure?"
* * ng-confirm-click="takeAction()" function
* * ng-confirm-condition="mustBeEvaluatedToTrueForTheConfirmBoxBeShown" expression
*/
angular.module('app').directive('ngConfirmClick', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', function() {
var condition = scope.$eval(attrs.ngConfirmCondition);
if(condition){
var message = attrs.ngConfirmMessage;
if (message && confirm(message)) {
scope.$apply(attrs.ngConfirmClick);
}
}
else{
scope.$apply(attrs.ngConfirmClick);
}
});
}
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment