1

I need a clue. How can I store data downloaded from the API?

  • All data downloading functions can be found in Service

  • I have several components

  • In one component I have a button that calls for downloading data from the API (Service injected through the constructor)

Where should this data be saved so that other components can use it?

If I return a value in the component in which the button was pressed from the data retrieval function, then only in this component I will have this data.

ImpoUserC
  • 599
  • 5
  • 16
  • The best use would be a database where you push all your data to. For example a specific table that stores the data of a specific endpoint. That way you can read the data in the other components. – Solaiman Mar 16 '19 at 12:05
  • Maybe [Redux](https://redux.js.org/) might be worth a shot. – pzaenger Mar 16 '19 at 12:23

2 Answers2

1

My suggestion is to save it in LocalStorage, but it depends based on your needs.

Check this one if it helps: Angular 6: saving data to local storage

LocalStorage is very well supported on different browsers: https://caniuse.com/#search=localstorage

TheBosti
  • 1,354
  • 13
  • 19
  • It is important that in the case of data changes, the components using these data are also refreshed. – ImpoUserC Mar 16 '19 at 12:10
  • You can achieve this with a service watching for changes. It will update the local storage and emits corespondent changes to subscribed components. – TheBosti Mar 16 '19 at 12:14
0

You can use Web Storage (Session storage and Local storage), but it depends on size of data. Local Storage and Session storage can store up to 10 MB i think, bit if your data size is much bigger , reconsider using IndexedDB. Here is a link to read: https://developers.google.com/web/ilt/pwa/working-with-indexeddb

Milos Kovacevic
  • 861
  • 1
  • 9
  • 20