AngularJS $rootScope variable exists, but not accessible

前端 未结 2 1134
囚心锁ツ
囚心锁ツ 2020-12-20 10:07

I set a $rootScope variable in one of my modules and now want to access that same $rootScope variable in another module. Thus far I can see that in both modules the variable

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-20 10:49

    I was just stuck in the same problem when I figured out that you have define those properties for $rootScope before the controllers or services load. So what I did was set inital values when the application runs. In your case it will be like:

    app.run(function($rootScope){
        $rootScope.test="variable";
    })
    

    `

提交回复
热议问题