angular/aio/content/errors/NG01101.md
Matthieu Riegler 8551631a5a docs(forms): change error code in filename to match enum value. (#49344)
Error code for bad AsyncValidatorFn is 1101 not 1003.

PR Close #49344
2023-03-07 17:38:01 +00:00

880 B

@name Wrong Async Validator Return Type @category runtime @shortDescription Async validator must return a Promise or Observable

@description Async validators must return a promise or an observable, and emit/resolve them whether the validation fails or succeeds. In particular, they must implement the AsyncValidatorFn API

export function isTenAsync(control: AbstractControl): 
  Observable<ValidationErrors | null> {
    const v: number = control.value;
    if (v !== 10) {
    // Emit an object with a validation error.
      return of({ 'notTen': true, 'requiredValue': 10 });
    }
    // Emit null, to indicate no error occurred.
    return of(null);
  }

@debugging Did you mistakenly use a synchronous validator instead of an async validator?

@reviewed 2022-06-28