-
-
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
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
/** | |
* 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