Skip to content

Instantly share code, notes, and snippets.

@fr6nco
Created September 19, 2018 22:56

Revisions

  1. fr6nco created this gist Sep 19, 2018.
    14 changes: 14 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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};
    })
    );
    };
    }