【发布时间】:2014-11-20 13:02:15
【问题描述】:
我正在使用$asyncValidators 来验证字段,但希望它仅在字段失去焦点时触发,而不是在每次更改时触发。这是可能的还是我必须使用$asyncValidators以外的其他东西?
使用$asyncValidators的代码示例(取自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;
});
};
【问题讨论】:
标签: javascript angularjs validation angularjs-directive