{ "id": "api/forms/NG_VALIDATORS", "title": "NG_VALIDATORS", "contents": "\n\n
\n
\n
\n \n API > @angular/forms\n
\n \n
\n \n
\n

NG_VALIDATORSlink

\n \n \n \n \n \n
\n \n \n\n
\n \n
\n

An InjectionToken for registering additional synchronous validators used with\nAbstractControls.

\n\n \n
\n \n \n \n \n const NG_VALIDATORS: InjectionToken<(Function | Validator)[]>;\n \n\n \n
\n

See alsolink

\n \n
\n\n\n \n \n\n \n
\n

Usage noteslink

\n

Providing a custom validatorlink

\n

The following example registers a custom validator directive. Adding the validator to the\nexisting collection of validators requires the multi: true option.

\n\n@Directive({\n selector: '[customValidator]',\n providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}]\n})\nclass CustomValidatorDirective implements Validator {\n validate(control: AbstractControl): ValidationErrors | null {\n return { 'custom': true };\n }\n}\n\n\n
\n\n\n\n
\n
\n\n\n" }