DEV Community

Discussion on: Angular: display a spinner on any component that does an HTTP request

Collapse
 
maszeh profile image
Thalles

Hi Stefanos,

I really liked your solution, I have implemented similar code in my application, and in both your code and mine the same issue occurs. When I make an isolated call to the backend everything happens normal, but if two calls occur at the same time (at the initialization of a component for example) in the interceptor arrive both, but in the subscribe of the BehaviorSubject only one arrives. I'm really stuck at this, any thoughts why this happens?

Collapse
 
elasticrash profile image
Stefanos Kouroupis

I ve only used that component in tables and charts and ...even when I had multiple charts per page, that still works fine. Bare in mind that each char subscribed to a different endpoint. So I've never tested it with multiple requests per component.

Because I find the issue intriguing...I am going to spend sometime tomorrow investigating it.

Collapse
 
maszeh profile image
Thalles

I found the problem in my application, it was not a problem because there were multiple subscriptions, the problem is that I was making the backend call at the same time as the component creation happened (changing the route and opening a screen did both) and when I made that call my component had not subscribed to BehaviorSubject yet. I just moved my call to the backend to ngAfterViewInit and everything worked as it should.