ngModelController debounce applies to the entire pipeline of parsers, validators, and change listeners (e.g. ng-change ).
Today there is no way (Angular v1.4) with ngModelOptions to allocate debounce delay for a specific validator.
But functionality is easily achieved by passing a delay parameter to its own asynchronous validator directive:
<input ng-model="val" foo-validator="{delay: 500}">
You do the actual delay using $timeout ; there is no reason to avoid using $timeout on the grounds that it is somehow less than the "Angular way"; this is not true.
The only trick is to make sure you cancel the previous pending verification request before executing a new one.
var pendingValidation; ngModel.$asyncValidators.foo = function(modelValue, viewValue){ if (pendingValidation) $timeout.cancel(pendingValidation); pendingValidation = $timeout(function(){ pendingValidation = null;
delay can be obtained from the parameter using the foo-validator either with binding to the selected area ( scope: {config: "=fooValidator"} ), or by directly using the $eval expression of the attribute expression in the right area:
var config = $scope.$eval(attrs.fooValidator); var delay = config.delay;
source share