Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watching local storage using angularjs

I am using a module called ngStorage for handling local Storage operations.(https://github.com/gsklee/ngStorage). Lets say I set an object in local storage $localStorage.something = true; How do I watch this object to find out if it is still available in local storage? I'v tried :

$scope.$watch($localStorage.something,function(newVal,oldVal){
   if(oldVal!==newVal && newVal === undefined){
     console.log('It is undefined'); 
  }
});

Basically I am trying to watch for when a user removes the object from local storage manually through chrome's console.Is this even possible??

like image 957
Dhruv Prakash Avatar asked Nov 11 '14 11:11

Dhruv Prakash


1 Answers

you can try:

$scope.$watch(function () { return $localStorage.something; },function(newVal,oldVal){
   if(oldVal!==newVal && newVal === undefined){
     console.log('It is undefined'); 
  }
})
like image 97
Marian Ban Avatar answered Oct 29 '22 03:10

Marian Ban