Ionic 4 Store JSON Call for use in multiple pages


I’ve got a app, where I want to retrieve data from a server and use these values from multiple pages. Prefer only one http call.

How do I store the data? In a Service? But how?

Yes, in a service. When calling the service ask it if there is data, if there is return it, otherwise you can assume it is the first call to it, so you would then make the remote call.

I figured as much. What i struggle to understand is this

If there is data it would return normal data, but if there is no data i would make a http call which would be a promise ( or similar).

How would I differentiate between the two returns. Or would I have to wrap the normal data in a promise as well perhaps ?

Thanks again

Found a good description of the problem here:

For some reason this works fine when running “ionic serve”, but on the device it seems like it does not store the variable for the Service.

Anyone know why?