Advertisement
Guest User

Untitled

a guest
Feb 4th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import {AsyncValidatorFn, AbstractControl } from '@angular/forms';
  2. export function userNameShouldBeUnique(): AsyncValidatorFn {
  3. return (control: AbstractControl): { [key: string]: any } => {
  4. return new Promise(resolve => {
  5. setTimeout(() => {
  6. if (control.value == 'mosh')
  7. resolve({ shouldBeUnique: true });
  8. else
  9. resolve(null);
  10. }, 1000);
  11. });
  12. }
  13. }
  14.  
  15. this.myForm = this.fb.group({
  16. username: [
  17. '',
  18. Validators.compose([Validators.required, forbiddenNameValidator(/bob/)]),
  19. Validators.composeAsync([userNameShouldBeUnique])
  20. ],
  21. password: ['', Validators.required]
  22. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement