0
  async onRegister(formRegister) {

    this.nbotoncito = false;
    this.spinner.show();

    if (this.ejercicio.idArea == "2") {
      console.log("ejercicios de fisica");
      await this.getTotalFisica();

    } else {
      console.log("cualquier cosa ajena a fisica");
      await this.getEjercicios_SubArea();

    }
  }


  async getTotalFisica() {

    await this.ejercicioService.getEjercicioTotalFisica().subscribe(
      res => {
         this.ejercicioTotal =   res;
        console.log("Respuesta del total de los ejercicios por FISICA: " + res);
      },
      err => console.log(err),
    );
  }

Before performing other actions in my onRegister I must have that array of exercises Total Loaded that method of getTotalPhysics comes from a backend hosted in heroku the function is as follows:

  getEjercicioTotalFisica(): Observable<EjercicioInterface[]> {
    console.log("Solcitando los ejercicos de fisica");
    return this.http.get<EjercicioInterface[]>(`${this.BASE_URL}/exercise/fisica`);
  }

I must have the compulsory array of exercises Total and necessary before carrying out any type of action in onRegister, and first the subscribe within onRegister is performed before that of getTotalExercises.

I don't receive errors, I'm just looking to fill that array before any action

1 Answer 1

1

I think you are mixing promises and Observables.

Convert your Observable to a promise:

async getTotalFisica() {
  try {
    this.ejercicioTotal = await this.ejercicioService.getEjercicioTotalFisica().toPromise();
  } catch (err) {
     console.log(err),
  }
}

(Note the .toPromise() at the end)

Sign up to request clarification or add additional context in comments.

2 Comments

" Failed to load resource: the server responded with a status of 404 (Not Found) The following error throws me your code
Okay, I don't see how my code can be related to that error. It seems to be related to the actual request sent in getEjercicioTotalFisica(). Have a look in the Network tab of the developer console, maybe there's a clue there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.