|
272 | 272 | ], |
273 | 273 | "description": "Angular Validator Function" |
274 | 274 | }, |
| 275 | + "Angular Async Validator": { |
| 276 | + "prefix": "ng-async-validator", |
| 277 | + "description": "Angular async validator snippet", |
| 278 | + "types": "typescript", |
| 279 | + "body": [ |
| 280 | + "import { Directive } from '@angular/core';", |
| 281 | + "import { NG_ASYNC_VALIDATORS, AbstractControl, AsyncValidator, ValidationErrors } from '@angular/forms';", |
| 282 | + "import { Observable, of } from 'rxjs';", |
| 283 | + "", |
| 284 | + "@Directive({", |
| 285 | + "\tselector: '[${validatorName}][ngModel]',", |
| 286 | + "\tproviders: [", |
| 287 | + "\t\t{ provide: NG_ASYNC_VALIDATORS, useExisting: ${className}, multi: true }", |
| 288 | + "\t]", |
| 289 | + "})", |
| 290 | + "", |
| 291 | + "export class ${className} implements AsyncValidator {", |
| 292 | + "\tvalidate(c: AbstractControl): Promise<ValidationErrors | null> | Observable<ValidationErrors | null> {", |
| 293 | + "\t\tif (!c.value) return of(null);", |
| 294 | + "", |
| 295 | + "\t\treturn of({", |
| 296 | + "\t\t\t'${validatorName}': true", |
| 297 | + "\t\t});", |
| 298 | + "\t}", |
| 299 | + "}" |
| 300 | + ] |
| 301 | + }, |
275 | 302 | "Angular Async Validator Function": { |
276 | 303 | "prefix": "ng-async-validator-fn", |
277 | 304 | "body": [ |
|
439 | 466 | "import { MatTabsModule } from '@angular/material/tabs';", |
440 | 467 | "import { MatToolbarModule } from '@angular/material/toolbar';", |
441 | 468 | "import { MatTreeModule } from '@angular/material/tree';", |
442 | | - |
| 469 | + |
443 | 470 | "const materialModules = [", |
444 | 471 | "\t\tA11yModule", |
445 | 472 | "\t\tBidiModule", |
|
476 | 503 | "\t\tMatButtonToggleModule,", |
477 | 504 | "\t\tMatTreeModule,", |
478 | 505 | "\t\t];", |
479 | | - |
| 506 | + |
480 | 507 | "@NgModule({", |
481 | 508 | "imports: [...materialModules],", |
482 | 509 | "exports: [...materialModules],", |
|
0 commit comments