Last active
August 29, 2015 13:57
-
-
Save Willmo36/9600515 to your computer and use it in GitHub Desktop.
Extending ngModel
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
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