This is my service :
.factory('$localstorage', ['$window', function($window) {
return {
set: function(key, value) {
$window.localStorage[key] = value;
},
get: function(key, defaultValue) {
return $window.localStorage[key] || defaultValue;
},
setObject: function(key, value) {
$window.localStorage[key] = JSON.stringify(value);
},
getObject: function(key) {
return JSON.parse($window.localStorage[key] || '{}');
}
}
}]);
and I want to store my json into it so I do like below in my controller:
$localstorage.set(JSON.stringify($scope.data));
I use this extension https://chrome.google.com/webstore/detail/storage-area-explorer/ocfjjjjhkpapocigimmppepjgfdecjkb to check, I found that my value is undefined:
..my json did passed through, but it goes into the key, not the value. Why?
它看起来像set
有一个键和一个值,而您只是设置第一个参数是键?
$localstorage.set('yourKey', JSON.stringify($scope.data));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.