0
내가 $의 asyncValidator 약속을 취소하려고 해결하지만 난 정의의 오류가 발생되고 생각하지, 여기 내 코드입니다 [ngModel : nopromise] 약속을 되 돌리는 비동기 유효성 검사기가 필요하지만 대신 '정의되지 않음'이 있습니다. 검증 기능이 약속을 반환 할 것으로 예상되는 반면,asyncvalidator 약속이
감사
내가 $의 asyncValidator 약속을 취소하려고 해결하지만 난 정의의 오류가 발생되고 생각하지, 여기 내 코드입니다 [ngModel : nopromise] 약속을 되 돌리는 비동기 유효성 검사기가 필요하지만 대신 '정의되지 않음'이 있습니다. 검증 기능이 약속을 반환 할 것으로 예상되는 반면,asyncvalidator 약속이
감사
방법 defer.resolve()
및 defer.reject()
를 제어합니다 defer.promise
의 상태, 그들은, 가 약속을 반환하지 않습니다. 대신 $q.when()
및 $q.reject()
을 사용해야합니다.
ngModel.$asyncValidators.duplicateModelName = function (modelValue) {
//if the user hasn't touched the input box I don't want to call the database code
if (ngModel.$pristine) {
return $q.when(true);
}
return modelManager.find(modelValue, false)
.then(function (data) {
if (data.exists === true) {
// Found a row
// this will reject the promise returned by modelManager.find()
return $q.reject('exists');
}
// Did not find a row
// no need to do anything, this promise is already
// resolved which will succeed the validation
});
}