Can $ watch be used to monitor changes in localStorage?
I have a factory to make setup / get a little easier
.factory('$localstorage', ['$window', function($window) { return { set: function(key, value) { $window.localStorage[key] = value; }, get: function(key, defaultValue) { return $window.localStorage[key] || defaultValue; }, setObject: function(key, value) { $window.localStorage[key] = JSON.stringify(value); }, getObject: function(key) { return JSON.parse($window.localStorage[key] || '{}'); } } }]);
In my controller I have
.controller('CodesCtrl', function($scope, $localstorage) { $scope.codes = $localstorage.getObject('codes'); ...
In another controller, I add to local storage. I want to make changes as soon as localStorage changes.
I saw several SO posts that use things like ngStorage, but ideally I would like to avoid this.
Is it possible? Can someone point me in the right direction?
source share