I have a RESTful web service that returns a list of products. I have an Angular application that calls this service through Ajax. I want to do this:
- check if the product list is in localStorage, if so, display it on the screen, then make an Ajax call in the background and refresh the screen when this service returns.
In fact, I want to first load and display from localStorage (my cache), and then replace it with the latest data from the service after it returns (and update the cache).
I want to download and display data from localStorage first, because if the user is disconnected, then obviously the Ajax request will not be completed, and I want this application to work when the user does not have an Internet connection.
How do you implement this on the Angular side? I looked at $ q and promises, but did not know how I can get it to "resolve" twice ...
source
share