AsyncValidator
interface
stable
An interface implemented by classes that perform asynchronous validation.
validate
Promise<ValidationErrors | null> | Observable<ValidationErrors | null>Method that performs async validation against the provided control.
@returns
Promise<ValidationErrors | null> | Observable<ValidationErrors | null>registerOnValidatorChange
voidRegisters a callback function to call when the validator inputs change.
@paramfn
() => voidThe callback function
@returns
voidUsage 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.
import { of } from 'rxjs';
@Directive({
selector: '[customAsyncValidator]',
providers: [{provide: NG_ASYNC_VALIDATORS, useExisting: CustomAsyncValidatorDirective, multi:
true}]
})
class CustomAsyncValidatorDirective implements AsyncValidator {
validate(control: AbstractControl): Observable<ValidationErrors|null> {
return of({'custom': true});
}
}
Jump to details