Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save raviagheda/44157d7986d0cbff4d5405f05f2e79d5 to your computer and use it in GitHub Desktop.
Save raviagheda/44157d7986d0cbff4d5405f05f2e79d5 to your computer and use it in GitHub Desktop.
form: FormGroup = new FormGroup({
    email: new FormControl('', [Validators.required], [this.customValidator()])
  })

  customValidator(): AsyncValidatorFn {
    return (control: AbstractControl): Observable<ValidationErrors | null> => {
      return this.loginService.checkUserExist({value: control?.value, type: 1})
      .pipe(map((res: {status: boolean, message: string}) => {
        return res?.status ? null : { duplicate: true };
      })).pipe(first())
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment