Created
April 15, 2014 17:24
-
-
Save gobijan/10749875 to your computer and use it in GitHub Desktop.
ng-really? An AngularJS directive that creates a confirmation dialog for an action. (props to asafge)
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-really-message="Are you sure?" ng-really-click="takeAction()" function | |
*/ | |
angular.module('app').directive('ngReallyClick', [function() { | |
return { | |
restrict: 'A', | |
link: function(scope, element, attrs) { | |
element.bind('click', function(e) { | |
e.stopPropagation(); // In case you cancel and don't want events to be propagated. | |
var message = attrs.ngReallyMessage; | |
if (message && confirm(message)) { | |
scope.$apply(attrs.ngReallyClick); | |
} | |
}); | |
} | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment