Created
March 31, 2015 00:35
-
-
Save gerasimua/347f1edc757d49e3913c to your computer and use it in GitHub Desktop.
Early click - click that happens before model changed on the checkbox and can prevent change of it
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
.directive('earlyClick', function() { | |
return { | |
require: '?ngModel', | |
link: { | |
pre: function(scope, iElement, iAttrs, ctrl) | |
{ | |
ctrl = null; | |
if (ctrl) { | |
//First way: reset the state inside a parser | |
ctrl.$parsers.push(function(val) { | |
console.log('I am being parsed'); | |
ctrl.$viewValue = null; | |
ctrl.$render(); | |
return null; | |
return val; | |
}); | |
} | |
// Second way: prevent the click | |
iElement.on('click', function($event) { | |
$event.stopImmediatePropagation(); | |
$event.preventDefault(); | |
//console.log('early click'); | |
}) | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment