Angular continues my function before the dialog response

Asked

Viewed 42 times

1

I have a function that calls a dialog if the SKU of a product is changed, but the function is being continued before the dialog result.

Is there any way to wait for the result and only then continue the function?

salvaAlteracoes(){
    for(let i=0;i<this.produtos.length;i++){
      if(this.produtos[i].id == this.produto.id){ //Quando encontrar na lista de produtos o id do produto que está alterando, verifica se o sku é diferente, se for, indica que foi alterado, então abre um dialog
        if(this.produtos[i].sku_prin != this.produto.sku_prin){
          const dialogRef = this.dialog.open(DialogConfirmacaoSKU, { panelClass: 'dialogpanel' });
          dialogRef.afterClosed().subscribe(result => {
            if (result == false) {
              return;
          }
        })
      }
    }
  }

The function continues here, but when it falls into the if() it does not wait for the afterClosed event and continues the function. How can I expect?

No answers

Browser other questions tagged

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