【发布时间】:2015-04-13 17:08:42
【问题描述】:
角度文档中的 asyncValidator 示例如下所示:
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;
});
};
如您所见,当返回一个被拒绝的承诺时,它传递了“存在”的值。这似乎意味着我可以在使用模型时访问这个值。这可能吗?
【问题讨论】: