firebase return

Asked

Viewed 47 times

0

Guys, I’d like to help with the firebase return, here’s the thing, in my angular design I have a component with some fields to be validated and a service only for validations, I’m having a hard time getting a return like I need, follow the code

my component form.ts have:

nextPage() {
if(this.serviceValidate.validaEmail(this.dataForm.value.gn_email)) {
   return;
 }
}

In my validation service I have Validausuario.service.ts:

  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 take a Boolean in this 3rd validation, already tested two ways thus

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 back without subscribing to Component ?

  • Why don’t you want to subscribe? Observables are Lazy they only run when you give the subscribe.

  • I am trying to do a validation on my component that has a form and an email field, for example, I did a service only to validate the email, I have if email == [email protected] True if email != '' Return true and if if email == firebase(table.usuario.email) Return true, I don’t know if I could explain

  • in the service I have these 3 validations if it is in email format if it is not empty and if any user in DATABASE does not have equal email, I want in the component to get only true or false

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.