angularjs Watching rootscope changes

后端 未结 2 1778
花落未央
花落未央 2021-01-03 17:54

I\'m trying to bind to rootscope so that I can set presence on a different server when the user logins. Here\'s my module.

angular.module(\'presence\', 
  [
         


        
相关标签:
2条回答
  • 2021-01-03 18:23

    Something needs to change $rootScope.currentUser for you to be able to notice any changes in it. You have shared the code for that.

    Also changes to $rootScope.currentUser need to take place inside the angularJS loop (http://docs.angularjs.org/guide/concepts). If it is done externally you can call $digest (http://docs.angularjs.org/api/ng.$rootScope.Scope#$digest)

    0 讨论(0)
  • 2021-01-03 18:26

    The syntax was $rootScope.$watch('currentUser') not $rootScope.$watch($rootScope.currentUser)

    0 讨论(0)
提交回复
热议问题