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
This commit is contained in:
Ramesh Thiruchelvam
2021-11-29 14:12:00 +05:30
committed by Dylan Hunn
parent 96dfc7af7c
commit 24baa5e61d
+20
View File
@@ -60,6 +60,26 @@ export const NG_VALIDATORS = new InjectionToken<Array<Validator|Function>>('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<ValidationErrors|null> {
* return Promise.resolve({'custom': true});
* }
* }
* ```
*
* @publicApi
*/
export const NG_ASYNC_VALIDATORS =