DEV Community

loading...

Discussion on: 9 Promising Promise Tips

Collapse
danielfrugoni profile image
DanielFrugoni

Hi, hope you can help me.
having this:
async searchDatoReg(locclave: string, locmail: string) {
this.mensaje = null;

return new Promise((resolve) => {
this.api.searchProductoLg(locclave, locmail).subscribe(
(data) => {
if (isUndefined(data[0])) {
this.op = 0;
this.filtrados = null;
console.log('tempx1:');
} else {
this.filtrados = { ...data };
this.op = 1;
console.log('tempx2:');

      }
    }
  )
}
)

}
then:
await this.searchDatoReg(locclave, locmail);

   if (this.op === 0){
      console.log('aca 1')
      console.log(JSON.stringify(this.filtrados));
      this.glo.asignaReg(this.filtrados[0].email,this.filtrados[0].clave,this.filtrados[0].nombre,this.filtrados[0].id);
    } else {
      console.log('aca 2');
      console.log(JSON.stringify(this.filtrados));
      this.glo.asignaReg(locmail,locclave,'',0);
    }

dosent syncronize the call, should first do this.searchDatoReg(..) then the rest
but never does it
any hint please