Created
November 12, 2013 13:06
-
-
Save asafge/7430497 to your computer and use it in GitHub Desktop.
ng-really?
An AngularJS directive that creates a confirmation dialog for an action.
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() { | |
var message = attrs.ngReallyMessage; | |
if (message && confirm(message)) { | |
scope.$apply(attrs.ngReallyClick); | |
} | |
}); | |
} | |
} | |
}]); |
Hi,
Im using a function just like this but i have an issue as other guys told, everytime l select cancel button the requested post it increments one at time, This way when l finally confirm the modal lt sends all the cumulative requests.
Someone have this issue?
thx
Thankyou! Good Stuff.
Thank you somuch...
nice na !!!
confirm action is called thrice :( and ajax post is called thrice in my case, can someone help?
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI - you don't need to clean this up afterwards w/
$destroy
because the element that has the event listener is already being removed which also kills thebind
(personally though, I would useon
overbind