Skip to content

Instantly share code, notes, and snippets.

@fr6nco
Created September 19, 2018 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fr6nco/10bd11151ba0c74cd0b773b045251c0d to your computer and use it in GitHub Desktop.
Save fr6nco/10bd11151ba0c74cd0b773b045251c0d to your computer and use it in GitHub Desktop.
export function emailExistsValidatorFn(userService: UserService, trueOnExists: boolean): AsyncValidatorFn {
console.log('validator triggered');
return (control: AbstractControl): Promise<ValidationErrors | null> | Observable<ValidationErrors | null> => {
console.log(userService);
return userService.checkIfEmailExists(control.value, trueOnExists).pipe(
take(1),
map((result: boolean) => {
console.log(result);
console.log('psovi nic');
return result ? null : {'emailexists': true};
})
);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment