I am storing data in two services but I have to redirect my user to facebook for authentication and paypal to make a payment and both times that clears out all the data stored in my services. I have placed some data in localstorage but it only stores strings afaik. How do I persistently store objects? or is that not possible.
            Asked
            
        
        
            Active
            
        
            Viewed 2,234 times
        
    2 Answers
0
            
            
        Store objects in local storage as strings,
Use JSON.stringify() to convert your object to string and JSON.parse() to parse it back into your object representation.
 
    
    
        Sᴀᴍ Onᴇᴌᴀ
        
- 8,218
- 8
- 36
- 58
 
    
    
        Monika Bozhinova
        
- 294
- 3
- 16
0
            
            
        You can stringify objects like that:
localStorage.setItem(JSON.stringify(obj));
Then to retrieve the object:
JSON.parse(localStorage.getItem('obj'));
Also there is a service for angular called localForage.
 
    
    
        jstice4all
        
- 1,878
- 4
- 22
- 33
- 
                    
- 
                    I meant I'll give storing stringified objects a try :P What is the max capacity you can use in localstorage and how do you check which devices or browsers dont allow using localstorage? – seanEd Feb 15 '17 at 13:17
- 
                    you can use this to check whether local storage exists or not if(typeof Storage !== "undefined") // local strage supported else // No web storage – Rahul Kumar Feb 15 '17 at 18:00
- 
                    Capacity varies a lot across browsers so see this table http://dev-test.nemikor.com/web-storage/support-test/ – jstice4all Feb 16 '17 at 06:15
- 
                    You may use localForage (this time it's not an angular service) https://github.com/localForage/localForage which is more crossbrowser. – jstice4all Feb 16 '17 at 06:23
