user5571323
user5571323

Reputation:

How to clear session storage using service

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

Upvotes: 1

Views: 9647

Answers (4)

Thabo Ketlhaetse
Thabo Ketlhaetse

Reputation: 58

Try

$sessionStorage.$reset()

Worked for me.

Upvotes: 0

Yaroslav
Yaroslav

Reputation: 466

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/

Upvotes: 1

Ajay Pandya
Ajay Pandya

Reputation: 2457

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) {}]);

Upvotes: 0

Nimesh.Nim
Nimesh.Nim

Reputation: 388

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

 $window.sessionStorage["windowKey"] = null;

Upvotes: 0

Related Questions