of course, you can use it directly $window.localStorage or with some angular directive like angular-localstorage which give you abstraction layer to use localStorage.
That stackoverflow post is very old. LocalStorage seems to work fine in my tests, although it would be interesting to find out exactly where the data is stored on disk.
Exactly. And how long / till what event is it guaranteed to be available? How do we find out?
I made a test app -and it reports that the data in localStorage is āsometimesā not available - not sure what event causes it. An app restart / phone restart / crash?
Iāve never seen the localStorage not being available so far. It should be persistent, restarting the app or phone shouldnāt cause it to be deleted. Uninstalling the app will delete it. If it behaves differently Iād consider that to be a bug in Cordova.
Hereās the āauthoritativeā source on how it behaves on iOS: CDVLocalStorage.m.
My app worked fine in an emulator with Android 5.1 last time I tried, but good to know about that issue in Chrome. I may decide to use SQLite instead of local storage.
That said, we canāt blame Ionic for bugs in Chrome or other projects.
This seems like a pretty big bug, I have an app for android with crosswalk that heavily relies on localStorage data.
Hope this doesnāt enter into crosswalk(using version 11.xx), will have to check every time I update it. For the moment localStorage stores just fine for several months already (updates included)
I have an app in the App Store for more than a year now that uses LocalStorage and never had any problems with that. Data was never lost, so I wouldnāt worry about that.
You have other options as well, like IndexedDB (only use that on Android), WebSQL, SQLite, or use PouchDB, which will encapsulate all of them. It so happens that I just wrote a blog post about using Ionic with PouchDB
BTW Ive not seen any problems with using local storage on iOS and Android. But it is really only designed to store simple stuff (credentials, preferences, etc). For more complex data, youāre better off with a real database. We are using Couchbase Lite locally and have a built an API on the server side that stores to a cluster of Couchbase servers. Syncing is handled by Couchbaseās builtin replication (two-way sync for āfreeā essentially) to Coucbase Sync Gateway.
My understanding (and that matches the experiments with my test app) is:
a) LocalStorage works well (tested on iOS 8.3 / iphone 5) - not randomly cleared.
b) However, there is one corner case in which I have seen that to be cleared repeatedly - and that is when the phone runs out of space. So my phone was very low on disk space - and periodically the icons on the phone face would go āCleaningā¦ā (where the app name is written) - and when that status showed up against my app - that meant that the localstorage has been wiped off.
I just made a 2 gigs of space on the device - and have had no problems of localstorage ever since.
I am not sure what android has available but for iOS there is NSUserDefaults that persist until the user wipes the app off the phone. Iām sure there is a plugin for that, and one equivalent for android, i just havenāt looked.
Iām also working on an ionic app and during testing phase on my phone I had no worries about local storage which was persistent.
Once deployed on Apple App Store some users complained about losing data time to time.
So my conclusion is that the local storage is not reliable at 100% because of iOS cleaning some apps or some strange behavior of safari in private mode.
Conclusion : dot not use local storage for sensitive data that you want to persist.
Personally I ended up using localforage and indexdb driver.