I'm using $asyncValidators to validate a field but would like it to trigger only when the field loses focus and not on every change. Is this possible or must I use something else than $asyncValidators?
Code example of using $asyncValidators (taken from the documentation)
ngModel.$asyncValidators.uniqueUsername = function (modelValue, viewValue) {
var value = modelValue || viewValue;
// Lookup user by username
return $http.get('/api/users/' + value).
then(function resolved() {
//username exists, this means validation fails
return $q.reject('exists');
}, function rejected() {
//username does not exist, therefore this validation passes
return true;
});
};