Angularjs corrector does not update ngClass

I'm pretty sure something stupid again. I study angularjs, so I don't get full coverage, but I get there. I tried everything and really looked for everything I could find, but nothing worked.

I am trying to do ng-class = "..." in my layout file, but the expression is set in my controller, but somehow it does not appear. It is displayed when I put it in the ng-view file. I get that it only displays part of the file, but I want it to also map the ng class to ng-view. Is this possible, or is it easier to just insert a div inside a partial html file.

Simple html file

<body> <ng-view ng-class="{ 'splash': splash=='splash' }"></ng-view> </body> 

My controller

 angular.module('xxx.splash') .controller('IndexCtrl', function($scope, $rootScope, config) { $rootScope.splash = 'splash'; $scope.login = function(e) { alert('Soon. How soon? Very soon.'); } }); 
+8
angularjs angularjs-scope
source share
1 answer

When you define a variable in the root area, you cannot access it in the same way as you define it in the local area. $rootScope variables can be accessed in AngularJS templates using $root.<variableName> , so your HTML file should be changed to this:

 <body> <ng-view ng-class="{ 'splash': $root.splash=='splash' }"></ng-view> </body> 

In this demo you can see the difference between $scope and $rootScope

+31
source share

All Articles