1

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

4 Answers4

1

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/

Yaroslav
  • 446
  • 4
  • 15
0

Set Window session key with NULL in logout service.. as below.

 $window.sessionStorage["windowKey"] = null;
Nimesh.Nim
  • 388
  • 2
  • 9
0

Follow the regular injection rule in angularjs.

app.service('service1', function(){});

//Inject service1 into service2

app.service('service2',function(service1){});

It is better to use Array injection to avoid minifying problem.

app.service('service2',['service1', function(service1) {}]);

Ajay Pandya
  • 2,417
  • 4
  • 29
  • 65
0

Try

$sessionStorage.$reset()

Worked for me.