I have something like this in a template I am creating
<div ui-view id="app" class="nng-3" ng-class="{ 'app-mobile': app.isMobile, 'app-navbar-fixed': app.layout.isNavbarFixed, 'app-sidebar-fixed': app.layout.isSidebarFixed, 'app-sidebar-closed': app.layout.isSidebarClosed, 'app-footer-fixed': app.layout.isFooterFixed }"></div>
The values app.layout.isNavbarFixed
, etc are initialized with either zero or one, and for the first time the page loads the appropriate classes are inserted into my div
. Any change after that though, by means of a button that sets those values, is not reflected on my class
attributes by ng-class
.
If I directly print those variables in my template, eg. {{app.layout.isSidebarFixed}}
I can see them changing from true
to false
and vice versa, but ng-class
will not update or remove any new classes.
I am not sure where to begin and look for the solution for this since with my limited knowledge I cant spot any obvious mistake immediately. Does anyone have any idea on what causes this issue?
A workaround of mine is to manipulate a model variable just for the ng-class toggling:
1) Whenever my list is empty, I update my model:
2) Whenever my list is not empty, I set another state
3) I use this additional model on my ng-class:
Update*: Also you can add any other states if needed and use at ng-class like:
Because you know, an initially empty list state is not equal with a list which is emptied by command.
Tried your variant. Have everything working. Please, check if your button click event is on $scope and AngularJS knows, that values changed.
For example, if function triggered by native DOM Event (some jQuery table updated or something) than you should use $apply function, to reflect changes on scope. Something like this:
In the mean time, check this jsfiddle
Update: Please check this jsfiddle out. This works in AngularJS 1.4.8, but doesn't in other, that support jsfiddle. From what I know, it's not really a best idea to do an assignment inside of expression, the controller is meant for this thing.
Probably the ng-class implementation is not considering "0" to be "false" as you expect, because it's doing an strict comparision with ===.
Try expressing the conditions like this: