Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda