mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Dylan Hunn
parent
96dfc7af7c
commit
24baa5e61d
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user