I am facing an issue with my form validation in which I am trying to check the existence of an email through HTTP validation, but encountering an error. Here is a snippet of my code:
Within the form component
constructor(
private _formBuilder:FormBuilder,
private _validationService:ValidationService
) { }
ngOnInit() {
this.resetForm = this._formBuilder.group({
email:['',Validators.compose([
this._validationService.emailExistsValidator
,Validators.required
])]
})
In the validationService
constructor(
public _authService:AuthService
){}
emailExistsValidator(control){
if(control.value != undefined) {
this._authService.checkExists("email")
.map(response => {
if (!response) {
return {'emailNotExists': true};
}
});
}
}
Within the _authservice (a service)
checkExists(value:string):Observable<any>{
return this._httpclient.get(this.authurl+value)
.map(response => {
return response
});
}
However, I am encountering the following error message:
Argument of type '((control: any) => void)[]' is not assignable to4 parameter of type 'ValidatorFn[]'.
Type '(control: any) => void' is not assignable to type 'ValidatorFn'.
Type 'void' is not assignable to type '{ [key: string]: any; }'.)
Can anyone provide guidance on how to resolve this issue?