0

I have an Angular application (9) and have multiple components that request calculation operations over rest and the displays the result in different editors. Now before I make the request I call a loading panel and after the request fininished I hide the loading panel in the finalize callback. Something like this:

this.isloading = false;
httpclient.get('http://localhost/calculate').pipe(finalize(() =>this.isloading=false).subscribe(v=>{
 //make some operations with the data and set editor values
});

now the loading panel disappers before all editor values are set. The finalize callback is called directly if the request fininishes, but how to call something like finalize, if the code inside of subscribe or error finishes?

Franki1986
  • 1,320
  • 1
  • 15
  • 40

1 Answers1

0

Call it at the end of your subscribe block? it looks like your finalize is being used in every "place" where you need it (it's not abstracted inside the service) so you might as well just call this.isLoading = false; as the last statement of your subscribe or error blocks

maury844
  • 1,210
  • 15
  • 25
  • 1
    Yes, this is the last option that I could so, call it at the end of subscribe and at the and of error callback. But so I will have to call it twice every time – Franki1986 Apr 01 '20 at 19:48