-
-
Save peccu/89c1d41d2e751bd6e36e to your computer and use it in GitHub Desktop.
This file contains hidden or 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()" ng-really-cancel-click="cancelAction()" function | |
*/ | |
angular.module('app').directive('ngReallyClick', [function() { | |
return { | |
restrict: 'A', | |
link: function(scope, element, attrs) { | |
element.bind('click', function() { | |
var message = attrs.ngReallyMessage; | |
if (!message){ | |
return; | |
} | |
if (confirm(message)) { | |
scope.$apply(attrs.ngReallyClick); | |
} else { | |
scope.$apply(attrs.ngReallyCancelClick); | |
} | |
}); | |
} | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add cancel action