I want to store a variable within $rootScope
. When I have a structure like this it all works OK, the second div displays the value:
<html ng-app>
...
<body>
<button ng-click="$rootScope.pr = !$rootScope.pr"></button>
<div ng-class="{some:$rootScope.pr}">{{$rootScope.pr}}</div>
</body>
But when I have a structure like this:
<body>
<div class="root-scope-value-1">{{$rootScope.mobileMenuCollapsed}}</div>
<div class="content-wrapper" ng-controller="MainController">
<nav class="navbar navbar-custom navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<div class="root-scope-value-2">{{$rootScope.mobileMenuCollapsed}}</div>
<button ng-click="$rootScope.mobileMenuCollapsed = !$rootScope.mobileMenuCollapsed">
The div with class root-scope-value-2
shows the value from $rootScope.mobileMenuCollapsed
, but the div with class root-scope-value-1
which is up the DOM doesn't. Why so?