Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best place to make continuous api call in angular throughout the application

Tags:

angular

I have a requirement where I have to make a api call every minute irrespective of current page, i.e throughout the app (Angular 7 app). what is best place to call this api (App component or anywhere better place), so that I din't make any design mistake. your suggestions will be appreciated

like image 675
Nitin Shekhar Avatar asked Dec 05 '25 15:12

Nitin Shekhar


1 Answers

I would do it in a Service which would be created and used by the AppComponent.

It's recommended that HttpClient calls are wrapped within services instead of being used in Components directly. This allows for greater flexibility for your application structure as you can reuse your your calls throughout the app, as well the ability to implement more advanced features such as caching.

And the timer would be in the AppComponent, not in the Service.

like image 122
jeprubio Avatar answered Dec 07 '25 13:12

jeprubio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!