Skip to content

Instantly share code, notes, and snippets.

@Willmo36
Last active August 29, 2015 13:57
Show Gist options
  • Save Willmo36/9600515 to your computer and use it in GitHub Desktop.
Save Willmo36/9600515 to your computer and use it in GitHub Desktop.
Extending ngModel
app.directive('ngModel', ['$timeout',function($timeout) {
return {
require: 'ngModel',
restrict: 'A',
link: function(scope, element, attrs, model) {
var timer,
delay = 1000;
element.bind('keydown change input', function () {
if (timer) {
$timeout.cancel(timer);
}
timer = $timeout(setVisited, delay);
});
element.bind('blur', setVisited);
function setVisited() {
model.$visited = true;
timer = null;
}
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment