Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

NG_ASYNC_VALIDATORS

An InjectionToken for registering additional asynchronous validators used with AbstractControls.

      
      const NG_ASYNC_VALIDATORS: InjectionToken<readonly (Function | Validator)[]>;
    

See also

Usage notes

Provide a custom async validator directive

The following example implements the AsyncValidator interface to create an async validator directive with a custom error key.

      
      @Directive({
  selector: '[customAsyncValidator]',
  providers: [{provide: NG_ASYNC_VALIDATORS, useExisting: CustomAsyncValidatorDirective, multi:
true}]
})
class CustomAsyncValidatorDirective implements AsyncValidator {
  validate(control: AbstractControl): Promise<ValidationErrors|null> {
    return Promise.resolve({'custom': true});
  }
}