admin管理员组文章数量:1416083
I have some data from different controllers that are stored in the sessionStorga using . The data is stored ok and it's available in the current session. The problem I am facing regards making a controller that will watch for changes in the webstorage.session I did this 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 the console.log output only once. I don't get any logs even though I change the content of webStorage.session. What could be the problem?
I have some data from different controllers that are stored in the sessionStorga using https://github./fredricrylander/angular-webstorage. The data is stored ok and it's available in the current session. The problem I am facing regards making a controller that will watch for changes in the webstorage.session I did this 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 the console.log output only once. I don't get any logs even though I change the content of webStorage.session. What could be the problem?
Share Improve this question asked Sep 26, 2014 at 13:58 exilonXexilonX 1,7613 gold badges27 silver badges51 bronze badges1 Answer
Reset to default 4webStorage.session
is only setting the value to $scope.mySessionStorage
one time upon the initialization of your controller. So that code above the watch is only firing one time.
Try watching the webStorage.session
value instead of the value in the controller:
$scope.$watch(function () {
return webStorage.session;
}, function (newVal, oldVal) {
console.log("The web storage has changed");
}, true);
本文标签: javascriptAngular js watch session StorageStack Overflow
版权声明:本文标题:javascript - Angular js watch session Storage - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745245115a2649520.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论