@coffeeee wrote:
Hey,
I am using the Ionic storage with a provider.
If my storage is empty (i.e. first time app starts), I would like to populate it with initially stored data from my Ionic storage.
What is the best approach for that?
I was thinking to perform something like this:
StorageProvider.ts: initData(){ return new Promise(resolve => { this.storage.set(this.storageKey, [some, dummy, data]); resolve(this.storage.get(this.storageKey)); }); } getStoredData(){ return new Promise(resolve => { this.storage.get(this.storageKey).then((data) => { resolve(data); }); }) } MainPage.ts: ionViewWillEnter() { this.myData = this.myDataProvider.getStoredData().then(data => { if (data == null) { this.myDataProvider.initData(); return (this.myDataProvider.getStoredData().then(data => data)); } else { return data; } }Any issues with that?
Other than that, should I fetch the data from a simple variable (i.e. array object), or should I make a http.get on a locally stored json file?
Thanks in advance!
Posts: 3
Participants: 2