Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
Angular Message Gets Triggered Before Service Call is Done

In my app, I have a button that enables users to calculate some data when it's clicked. To do the calculation, a service from the back-end is called. After the service finishes the calculation, I display a message that says 'Done'. But the message appears way before the service finishes calculation. Here's my code, how can I fix this?

 sendCalculateMaterialPlanDetail() {

    this.confirmDialogRef = this._dialog.open(FuseConfirmDialogComponent, {
      disableClose: false,
    });

    this.confirmDialogRef.componentInstance.confirmMessage =
      "Will start to calculate.";

    this.confirmDialogRef.afterClosed().subscribe((result) => {
      if (result) {
        this._productionService
          .sendCalculateMaterialPlanDetail(this.materialPlan)
          .subscribe((response: IMaterialPlan) => {
            this.materialPlan = response;
          });
      }
      this._messages.Show(
        "DONE",
        "DONE",
        3
      );
    });
  }
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

sendCalculateMaterialPlanDetail() {

    this.confirmDialogRef = this._dialog.open(FuseConfirmDialogComponent, {
      disableClose: false,
    });

    this.confirmDialogRef.componentInstance.confirmMessage =
      "Will start to calculate.";

    this.confirmDialogRef.afterClosed().subscribe((result) => {
      if (result) {
        this._productionService
          .sendCalculateMaterialPlanDetail(this.materialPlan)
          .subscribe((response: IMaterialPlan) => {
            this.materialPlan = response;
            this._messages.Show(
            "DONE",
            "DONE",
            3
            );
          });
      }
      
    });
  }

show the text inside the inner subscribe(service result handler)

about 4 years ago · Santiago Trujillo Relatório

0

You can use the key words await and async

async sendCalculateMaterialPlanDetail() {

    this.confirmDialogRef = this._dialog.open(FuseConfirmDialogComponent, {
      disableClose: false,
    });

    this.confirmDialogRef.componentInstance.confirmMessage =
      "Will start to calculate.";

    this.confirmDialogRef.afterClosed().subscribe((result) => {
      if (result) {
      /////////////////////////////////////////////////here
        await  this._productionService
          .sendCalculateMaterialPlanDetail(this.materialPlan)
          .subscribe((response: IMaterialPlan) => {
            this.materialPlan = response;
          });
      }
      this._messages.Show(
        "DONE",
        "DONE",
        3
      );
    });
  }
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda