I would like to have several global variables that are associated with the user interface (i.e. the open state of the menu). I decided to put them in $rootScopeso that they are always available.
This is the code I wrote:
(function (angular) {
angular
.module("App", [])
.run(["$rootScope", function ($rootScope) {
angular.extend($rootScope, {
ui: {
menu: false,
...
}
});
}]);
})(angular);
I deliberately used angular.extendto make sure that successive manipulations with the same object were saved. And I think this is also cleaner and safer than adding multiple properties to any object one by one.
Problem
The top code does nothing. When I launch my application and check the root area by calling:
$("body").scope().$root.ui
undefined, - ui ng-click . ui ... , run(), angular , ng-click, .
?