I want to make a custom async validator in my Angular project.
I'm using firestore for my DB, and the structure of it is
colloection (profiles) - doc ( email, username )
this is my form code,
this.registerForm = this.formBuilder.group({
email : ['', Validators.compose([Validators.required, Validators.email]), this.emailCheck.bind(this) ],
password : ['', Validators.required],
confirmPassword : ['', Validators.compose([Validators.required, this.isEqualPassword.bind(this)])]
})
but i don't know how to make this.emailCheck.bind(this)
function.
what I did is
emailCheck(control: FormControl) {
control.valueChanges
.debounceTime(1500)
.switchMap(val => this.emailValid(val))
.subscribe((res) => {
return res ? null : {emailAvailable : true}
})
emailValid(val) : Observable<any> {
let ref = this.afs.collection(`profiles`, ref => ref.where('email', '==', val))
return ref.valueChanges()
and then I get error
please let me know how to fix this.