Angular js storage session session

I have data from different controllers that are stored in sessionStorga using https://github.com/fredricrylander/angular-webstorage . Data is stored in order and available in the current session. The problem I am facing is creating a controller that will monitor changes to webstorage.session. I did it like this:

app.controller(
    'updateDataController',
    ['$scope','$http','$sce','$location','$routeParams', '$rootScope', '$document', 'webStorage', '$interval', 'md5',
        function($scope,$http,$sce,$location,$routeParams, $rootScope, $document, webStorage, $interval, md5) {

            $scope.mySessionStorage = webStorage.session;

            $scope.$watch('mySessionStorage', function (newVal, oldVal) {
                 console.log("The web storage has changed");
            }, true);

        }
    ]);

I get console.log output only once. I do not receive any logs even if I modify the contents of webStorage.session. What could be the problem?

+4
source share
1 answer

webStorage.session $scope.mySessionStorage . .

webStorage.session :

$scope.$watch(function () {
   return webStorage.session;
}, function (newVal, oldVal) {
   console.log("The web storage has changed");
}, true);
+3

All Articles