[英]async validator (AsyncValidatorFn) is never subscribed to
I wrote a custom Form Validator but in errors
it just has "_isScalar": false, "source": { "_isScalar": false, "source": { "_isScalar": false, "source": {"_isScalar": false}, "operator": {}}, "operator": {"total": 1}
and the form is never valid.我写了一个自定义表单验证器,但在
errors
它只有"_isScalar": false, "source": { "_isScalar": false, "source": { "_isScalar": false, "source": {"_isScalar": false}, "operator": {}}, "operator": {"total": 1}
并且表单永远无效。
This is my Validator:这是我的验证器:
export function asyncEmailValidator(): AsyncValidatorFn {
return (control: AbstractControl): Observable<ValidationErrors | null> => {
return of(control.value).pipe(
map(res => {
return res && res.indexOf('example.de') < -1 ? { eMailUnavailable: true } : null;
}),
take(1), finalize(() => {})
);
};
}
This is how i use it:这就是我使用它的方式:
emailFormControl = new FormControl('', [
Validators.required,
Validators.email,
asyncEmailValidator()
]);
From debugging i found that the map Block where i check for example.de is never reached and i fail to understand why.通过调试,我发现从未到达我检查 example.de 的 map 块,我不明白为什么。 The function itself is used and output before the inner return is shown.
在显示内部返回之前使用 function 本身和 output。
I saw this structure in multiple examples online but it just doesn't seem to work for me.我在网上的多个示例中看到了这种结构,但它似乎对我不起作用。
I am using @angular/forms
10.0.14
我正在使用
@angular/forms
10.0.14
Asynchronous validators should be specified as a third argument as follows:异步验证器应指定为第三个参数,如下所示:
new FormControl('', [Validators.required, Validators.email], [asyncEmailValidator()]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.