Hey there!
I have problems with using the LocalStorage via @Ionic/Storage properly. I’ve tried several ways to make it work, but haven’t had any luck yet. So either something is buggy or I make a trivial mistake somewhere, probably the latter.
I’ve implemented the Storage Module as described in the Documentation and testing on my local machine with Chrome.
Here’s what happens in a nutshell:
- I start up a fresh build of my app, starts at the Login Screen
- I insert my credentials and click the Login Button
- I save some initial data in the localStorage (I confirmed that it is actually saved, yes.)
- An API call is made to verify the login data
- If login is correct, the user gets sent to another Page in the App
- Said page then automatically makes an API call on load and retrieves some values from the localStorage
This is where it breaks! For some reason using the storage.get(‘key’).then((val) => { this.variable = val }); is not returning the data from the storage, which is definitly in there.
A weird thing with this is though, when I refresh the browser page then it suddenly can retrieve the data. I’m confused by this.
I do check in my app.component.ts for this.storage.ready().then… to make sure it is loaded. But doesn’t seem to make any difference.
It makes no sense for me and maybe I’m missing something? Anyone here can help me out to get it working? Also, on a side note, are there any reliable and straight forward alternatives to @ionic/storage that work on Android, iOS and possibly Browser (for development reasons)?
Thanks! I can post more code snippets, if needed.