AngularJS calling a method when its get new data in localStorage

前端 未结 1 583
挽巷
挽巷 2021-01-28 08:58

I am using angularJS localstorage and i injected this very well but problem in code.

I want when localstorage gets new data, so that its call a function $scope.get

相关标签:
1条回答
  • 2021-01-28 09:50

    Use the storage event:

     angular.element(window).on("storage", $scope.getAllContact);
    
     $scope.$on("$destroy", function() {
         angular.element(window).off("storage", $scope.getAllContact);
     });
    

    For information, see

    • MDN Window API Reference - storage_event
    • MDN Web API Reference - StorageEvent
    0 讨论(0)
提交回复
热议问题