I would like help with the return of firebase, this is the following, in my angular project I have a component with some fields to validate and a validation-only service, I am having difficulty getting a return as I need it, follow the code
My form.ts component I have:
nextPage() {
if(this.serviceValidate.validaEmail(this.dataForm.value.gn_email)) {
return;
}
}
In my validation service I have ValidaUsuario.service.ts I have:
validaEmail(email: string): any {
let valida = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2,3}$/;
//1º validação
if(email == '') {
this.snackbar.openSnackBar('Campo email obrigatório');
return false;
//2º validação
} else if(!valida.exec(email)) {
this.snackbar.openSnackBar('Email não é valido, tento outro!');
return false;
}
// 3º validação
var data = this.db.list(this.PATH,
ref => ref.orderByChild('gn_email')
.equalTo(email))
.valueChanges();
}
If possible, I would like to get a boolean in this 3rd validation, I already tested two ways so
var data = this.db.list(this.PATH,
ref => ref.orderByChild('gn_email')
.equalTo(email))
.valueChanges();
and so:
firebase.database().ref(this.PATH)
.ref.orderByChild('gn_email')
.equalTo(email)
.on('child_added', function(snapshot) {
console.log(snapshot.exists())
var data = snapshot.exists();
// })
How to get the return without doing the subscribe in the component?