How to clear session storage using service

user5571323 picture user5571323 · Feb 9, 2016 · Viewed 9k times · Source

In angularjs , i have a logout button. To clear the session storage im using window.sessionStorage.clear(). But I want to clear session storage using service. The service im using is LocalCacheService .How to clear sessionStorage using this service

'controller': ["$scope","LocalCacheService", function ($scope,LocalCacheService) {
console.log("Logout Controller called....");
$scope.Logout = {
}
}]

In that logout what should i add to clear session storage using service

Answer

Yaroslav picture Yaroslav · Feb 9, 2016

You are able to clear all data stored within sessionStorage if required.

In order to clear everything stored by your application within sessionStorage you should use the following:

$sessionStorage.empty();

See the link http://ghost.scriptwerx.io/angularjs-sessionstorage/