简体   繁体   中英

AngularJS localStorage

I am new to AngularJS. I have a bit difficulty in clearing my localStorage items. I tried clearing using localStorage.clear() or by using return localStorage = null, Still it is not getting cleared. Here is my sample code for signout.

$rootScope.signout = function() {
    localStorage.clear();
    $http.get('auth/signout');
    $location.path('/auth/login');
};

Try to use it like that

app.controller('YourController',function(..., $window)

then

$window.localStorage.clear();

I don't know how you inject $localStorage , or how your localStorage variable is defined, but you can clean your local storage with:

Using ngStorage :

$localStorage.$reset();

Using $window :

$window.localStorage.clear();

try with $window.localStore.removeItem('key');

where 'key' is the name of the property you want to delete from the localStorage.

If doesn't work please write your full code and maybe I can help you better.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM