angularjs and localStorage change event

前端 未结 4 1810
梦如初夏
梦如初夏 2020-12-09 03:14

I store some data in the localStorage

what I want in my angularjs app is that when the data in the localStorage changed, the app rerender the app, how can I do this?

4条回答
  •  情深已故
    2020-12-09 03:41

    Incidentally, I've created yet another localStorage module for AngularJS which is called ngStorage:

    https://github.com/gsklee/ngStorage

    Usage is ultra simple:

    JavaScript

    $scope.$storage = $localStorage.$default({
        x: 42
    });
    

    HTML

    
    

    And every change is automagically sync'd - even changes happening in other browser tabs!

    Check out the GitHub project page for more demos and examples ;)

提交回复
热议问题