Skip to content

Instantly share code, notes, and snippets.

@peccu
Forked from asafge/ng-really.js
Last active February 11, 2018 13:42
Show Gist options
  • Select an option

  • Save peccu/89c1d41d2e751bd6e36e to your computer and use it in GitHub Desktop.

Select an option

Save peccu/89c1d41d2e751bd6e36e to your computer and use it in GitHub Desktop.
/**
* 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);
}
});
}
}
}]);
@peccu
Copy link
Copy Markdown
Author

peccu commented Mar 20, 2015

add cancel action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment