What's up with ionic2 storage?


I’m new to Ionic and I’m up and about playing around with the framework. I wanted to test data persistence over app restarts. I was trying ionic 2’s storage on the ionic 2 docs, which I believe I followed well but can’t get the data to persist (both on browser and Android device at 6.0).

Basically what I did is I have a text input which I will save its content via storage. On app restart, I’ll display a toast of the last saved text in the input, the following way (presentToast is just a function to handle toast and ‘name’ obviously is the key):

this.storage.get('name').then((val) => {
			val ? this.presentToast(val) : this.presentToast("nothing saved!");

That is done on an ionViewWillEnter() hook so its called every time the page becomes active.

But on app restart (after saving an item to storage), I get the latter toast (i.e. “nothing saved!”). What am I doing wrong?

Another thing to notice is that, on the browser console, it says Ionic Storage driver is asyncStorage. I tried to play around with storage.js such that I changed the driver to LocalStorageWrapper. I believe the docs said it should be able to do things automatically but oh well. After that change, I got the data to persist on the browser (i.e. saved value shows on the toast). However, on my android device, it’s still the same case.


May be due to this issue: driftyco/ionic-storage#20