const asyncValidator: AsyncValidatorFn = (control: AbstractControl) => { const email = control.value; const values$ = control.valueChanges; return values$.pipe( debounceTime(1000), distinctUntilChanged(), switchMap((value) => userService.userEmailExists(value)), map((exists) => { if (exists) { return { userExists: true }; } else { return null; } }), first(), catchError((err) => { return NEVER; // non completa mai e resta in pending }) ); };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter