Reputation: 69
I have an Angular 4 application that currently has two components, CompA and CompB. CompA is fetching books through a http service and displaying it in a table. CompB is just showing some static data. I am navigating between these two components. The problem is when CompA is done fetching data and I navigate to CompB and then come back to CompA, it again fetches the data through http service. This way, I'm sending back to back requests to server. Is there any generic way to tackle this issue? I'm developing a big application and that application have a lot of such components.
Upvotes: 0
Views: 343
Reputation: 1523
Your best approach would be to have the http call and local caching of it's output in a service. The component will request the data from this service when it is required and the service will keep it's state during the lifetime of the application.
Upvotes: 2