html5 - AngularJS local storage service wrong return -
i have service in app. service set , user in localstorage. getuser function returning json.parse function not object.
anybody know how resolve insue?
the code here:
.service('userservice', function() { // purpose of example store user data on ionic local storage should save on database var setuser = function(user_data) { window.localstorage.extract = json.stringify(user_data); }; var getuser = function(){ console.log(json.parse(window.localstorage.user || '{}')); return json.parse(window.localstorage.user || '{}'); }; var clearuser = function(){ delete window.localstorage.user; }; return { getuser: getuser, setuser: setuser, clearuser: clearuser }; })
thanks
i use localstorage.get/set item methods below. service like
.service('userservice', function() { var getuser = function(){ return json.parse(window.localstorage.getitem('user')); }; var setuser = function(user){ json.stringify(window.localstorage.setitem('user', user)); }; return { getuser: getuser, setuser: setuser }; })
Comments
Post a Comment