Angular4 wait for callback to API without timeout

0

If you can help me, please.

I need to make a call in the API but there are a lot of data and I want Angular to wait for this term, at that moment I put a promise but it does not wait and as long as the API is handling the data on the NodeJS side the Angular makes a second call in the API by running over and creating two calls at the command line. My service code:

buscarConsumo(dadosConsumo): Promise<any> {
return this.http.post('${API_AZURE}/buscarconsumoperiodo', dadosConsumo)
  .toPromise()
  .then((data) => data)
  .catch((e) => console.log('Erro na Service', e));
}

My API takes 3 to 4 minutes to finish, I'll handle this in a future bank, but at the moment I need to bring the data to the client side, I tried to put timeout more unsuccessfully.

    
asked by anonymous 23.07.2018 / 15:21

1 answer

0

With Eduardo's advice it worked, putting then on the component it waits for the end of the request on the server until the end:

buscarConsumoTotalResourceGroup(f) {

this.loading = true;
this.consumoService.buscarConsumoTotalResourceGroup(this.consumo)
.toPromise()
.then((consumoResourceG: any) => {
  this.consumoResourceG = consumoResourceG;
  this.loading = false;
  console.log('Retorno de Consumo Total por ResourceGroup: ', consumoResourceG);
});

}

    
26.07.2018 / 17:16