添加验证器是否有任何理由覆盖现有的异步验证器?
我在formGroup上使用了角12和formGroup()。医生说:“不影响其他验证程序。”
一旦我添加了验证器,异步验证器就不再触发了。
public testValidator(): AsyncValidatorFn {
return (control: AbstractControl): Observable<ValidationErrors | null> => {
return of({wrongAuthority: 123});
}
}
public authorityValidator(control: AbstractControl) {
return {wrongAuthority: 12333};
}
this.form = this._fb.group({...}, { asyncValidators: this.testValidator()});
this.form.addValidators(this.authorityValidator);
this.form.updateValueAndValidity();发布于 2021-09-06 15:14:53
对角码的研究提供了一些结果:
(this as {errors: ValidationErrors | null}).errors = this._runValidator();
(this as {status: FormControlStatus}).status = this._calculateStatus();
if (this.status === VALID || this.status === PENDING) {
this._runAsyncValidator(opts.emitEvent);
}如您所见,首先执行同步验证器并设置控制状态,然后如果他抛出错误,则状态值将忽略异步验证器。这事儿可以理解。
P.S. 用console.log执行验证器
https://stackoverflow.com/questions/69076487
复制相似问题