Reputation: 390
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??
Upvotes: 11
Views: 14789
Reputation: 8178
you can try:
$scope.$watch(function () { return $localStorage.something; },function(newVal,oldVal){
if(oldVal!==newVal && newVal === undefined){
console.log('It is undefined');
}
})
Upvotes: 22