more_horiz
@angular/formscode
Validator
interface
stable
An interface implemented by classes that perform synchronous validation.
On this page
API
interface Validator { validate(control: AbstractControl<any, any, any>): ValidationErrors | null; optional registerOnValidatorChange(fn: () => void): void;}
validate
ValidationErrors | nullMethod that performs synchronous validation against the provided control.
registerOnValidatorChange
voidRegisters a callback function to call when the validator inputs change.
@paramfn
() => voidThe callback function
@returns
voidUsage Notes
Provide a custom validator
The following example implements the Validator interface to create a
validator directive with a custom error key.
@Directive({
selector: '[customValidator]',
providers: [{provide: NG_VALIDATORS, useExisting: forwardRef(() => CustomValidatorDirective), multi: true}]
})
class CustomValidatorDirective implements Validator {
validate(control: AbstractControl): ValidationErrors|null {
return {'custom': true};
}
}
Jump to details