Erro abaixo na hora de validar um campo do formulário com método assíncrono:
import { AbstractControl } from '@angular/forms';
import { VerificaEmailService } from './verifica-email-service';
import { Injectable } from '@angular/core';
import { debounceTime, switchMap, map, first } from 'rxjs/operators';
@Injectable({ providedIn: 'root'})
export class EmailTakenValidationService {
constructor(private verificaEmailService: VerificaEmailService) {}
checkEmailTaken(){
return (control: AbstractControl) => {
return control
.valueChanges
.pipe(debounceTime(500))
.pipe(switchMap(email => {
return this.verificaEmailService.verificarEmail(email);
}))
.pipe(map(isTaken => isTaken ? {emailTaken: true } : null))
.pipe(first());
};
}
}
(control) => { return control .valueChanges .pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_0__["debounceTime"])(500)) .pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_0__["switchMap"])(email => { return this.verificaEmailService.verificarEmail(email); })) .pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_0__["map"])(isTaken => isTaken ? { emailTaken: true } : null)) .pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_0__["first"])()); }