const
An InjectionToken
for registering additional synchronous validators used with AbstractControl
s.
const NG_VALIDATORS: InjectionToken<(Function | Validator)[]>;
The following example registers a custom validator directive. Adding the validator to the existing collection of validators requires the multi: true
option.
@Directive({ selector: '[customValidator]', providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}] }) class CustomValidatorDirective implements Validator { validate(control: AbstractControl): ValidationErrors | null { return { 'custom': true }; } }
© 2010–2021 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v12.angular.io/api/forms/NG_VALIDATORS