這是我的代碼。如何清除離子中的localstorage數據?
$scope.logout=function(){
localstorage.set('user_id', "");
localstorage.set('access-token', "");
localstorage.set('isUserTraverseColony', 0);
localstorage.set('isStarted', 0);
$window.localStorage.clear();
$window.localStorage.removeItem(access-token);
$ionicHistory.clearCache();
$ionicHistory.clearHistory();
};
我想從我的localStorage刪除訪問令牌變量,它做工精細的瀏覽器當我使用
$window.localStorage.clear();
$window.localStorage.removeItem(access-token);
但它不工作我的應用程序。
,這裏是我的localStorage廠
angular.module('starter.controllers').factory('localstorage', ['$window', '$localStorage','$q', function ($window, $localStorage,$q) {
return {
set: function (key, value) {
var deferred = $q.defer();
$window.localStorage[key] = value;
deferred.resolve(1);
return deferred.promise;
},
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] || '{}');
}
}
}]);
任何想法?
'access-tokan'是一個錯字,或者你在代碼中有這樣的錯誤嗎?你嘗試過使用'localstorage.clear()'(刪除'$ window')嗎? – JcDenton86
我正在使用本地存儲工廠,我編輯了我的問題 –