Can I or Should I use a Global variable in Angularjs to store a logged in user?

前端 未结 4 1008
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 08:41

I\'m new to angular and developing my first \'real\' application. I\'m trying to build a calendar/scheduling app ( source code can all be seen on github ) and I want to be a

4条回答
  •  一生所求
    2020-12-22 09:21

    You can have a global user object inside the $rootScope and have it injected in all your controllers by simply putting it into the arguments of the controller, just as you do with $scope. Then you can implement functionalities in a simple check: if($rootScope.user). This allows you to model the user object in any way you want and where you want, acting as a global variable, inside of Angular's domain and good practices with DI.

提交回复
热议问题