Issue
I am working on an Ionic phone app using AngualrJs as the framework. Now I faced an issue. I don't want my app to send an HTTP request to my backend(which use Ruby on Rails) API to do a manual test.
So I'm wondering what's the best practice to pass a mock JSON data as a response when I want to call the API.
I'm not familiar with Angular and Ionic, I can find some tutorials on both sides but I don't know what's is the best practice if use them together.
Solution
You can either store the data in localStorage
after the first hit and read the data from localStorage
every-time whenever you need.
https://medium.com/@petehouston/awesome-local-storage-for-ionic-with-ngstorage-c11c0284d658
Or you can use
$httpBackend
by saving json files locally and injecting them back when the application tries to hit the network . One limitation here, you cannot update the json file later after the user have installed the application.
So, localStorage
is preferred if you want to cache the data you have received from network.
Answered By - Atul Sharma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.