Skip to content

Instantly share code, notes, and snippets.

@gerasimua
Created March 31, 2015 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerasimua/347f1edc757d49e3913c to your computer and use it in GitHub Desktop.
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
.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