How to use Local Storage


#1

Just Creating add to cart Example but need some suggestion please help me

How to store all items of cart locally and Once User Confirm the Order then all Item Push the Server.


#2

you need no localstorage for that (and i do not know how many data you will store).
Localstorage is very tiny and is for storing flags like “use is authorized” or the authorized user id… not for complex datastructures, because they can only be stored as strings.

You can use an own angularjs service for that. the service can share data between views and will be cleared, if you reload the whole page/app.


#3

how i will know how many item in cart or how to remove can give you detail explanation or any sample.


#4

To store your cart in LocalStorage, you have to convert it as a JSON string using angular.toJson().
The interest of storing it is that you can have long lasting carts where user quits and re-starts your app.
There are plenty of examples, even in the ionic blog.


#5

but for those usecases i would use indexeddb or local db system like sqlite.

If you really want to use localstorage, i am using a littel wrapper for that:


#6

hi bengtler,

I think SQLite is better idea , so i was trying to install from this link https://blog.nraboy.com/2014/11/use-sqlite-instead-local-storage-ionic-framework/
but after installation app showing blank screen

I followed all step line by line but still showing error

please help me to resolve this error