Reputation: 1
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');
};
Upvotes: 0
Views: 189
Reputation: 384
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.
Upvotes: 0
Reputation: 18309
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();
Upvotes: 1
Reputation: 686
Try to use it like that
app.controller('YourController',function(..., $window)
then
$window.localStorage.clear();
Upvotes: 1