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');
};

3 Answers 3

1

Try to use it like that

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

then

$window.localStorage.clear();
Sign up to request clarification or add additional context in comments.

Comments

1

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();

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.