ngStorage
ngStorage copied to clipboard
fire events when item is added or removed.
This is helpfull when working with tokens in my case, when token is deleted from localstorage (logout functionality) i want to show a dialog box in the same browser in all tabs saying that logged out on another tab, please reload. For this situation how i want to detect the toke is deleted. so may it is easy to have an events to fire or callback functionality.
Well I am not the professional on the topic. But just use a watch.
pseudocode
$rootScope.$watch(function() {
return $localStorage.sendQueue.length
}, function watchCallback(newValue, oldValue) {
if (newValue > oldValue) {
$timeout(flushQueue, 3000);
}
});
Hi @Webrow , Actually i want to call some function only when the token is deleted, but as you said it will fired as many times the token is updated in the localStorage which is not required. and Also rather tahn watch its easy to subscribe to events with respect to performance.
Could probably add code to broadcast when changes occur. Then you would need to $rootScope.on() for that event. If you want to create a PR that would be cool. If not I'll add it to my longish list of things to do.