From 24baa5e61d3c8f11a9dae0c51b0510757d5fe43e Mon Sep 17 00:00:00 2001 From: Ramesh Thiruchelvam Date: Mon, 29 Nov 2021 14:12:00 +0530 Subject: [PATCH] docs(forms): add an example for async validator token (#44301) to be consistent with the validator token, have the example code for the async validator token. PR Close #44301 --- packages/forms/src/validators.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/forms/src/validators.ts b/packages/forms/src/validators.ts index 99200c8bca3..83dc8efe7d6 100644 --- a/packages/forms/src/validators.ts +++ b/packages/forms/src/validators.ts @@ -60,6 +60,26 @@ export const NG_VALIDATORS = new InjectionToken>('NgVa * * @see `NG_VALIDATORS` * + * @usageNotes + * + * ### Provide a custom async validator directive + * + * The following example implements the `AsyncValidator` interface to create an + * async validator directive with a custom error key. + * + * ```typescript + * @Directive({ + * selector: '[customAsyncValidator]', + * providers: [{provide: NG_ASYNC_VALIDATORS, useExisting: CustomAsyncValidatorDirective, multi: + * true}] + * }) + * class CustomAsyncValidatorDirective implements AsyncValidator { + * validate(control: AbstractControl): Promise { + * return Promise.resolve({'custom': true}); + * } + * } + * ``` + * * @publicApi */ export const NG_ASYNC_VALIDATORS =