1

How can I use ngClass map syntax with the && and ! boolean operators?

<div class="tbTileContent"
    ng-class=  
    "{'highlight': ((obj.Count == 1 &&  
         setActionType != 1 && setActionType != 20 )},[obj.BackgroundColor,obj.ColumnColor]">

Does not work. Is this possible some other way?

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
Sadeghbayan
  • 1,163
  • 2
  • 18
  • 38

1 Answers1

0

Use equality checks with reference to the rootScope to simplify debugging, and use the developer tool to check CSS specificity:

.foo { color: red; }
.bar { color: blue; }
.baz { color: green; }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<script>
  function bar($rootScope)
    {
    $rootScope.conditionA = true;
    $rootScope.conditionB = function() { return true; };
    }
  
  angular.module('foo',[]);
  angular.module('foo').run(bar);
</script>
<div ng-app="foo">
  <div class="existing" ng-class="{baz: conditionA && conditionB(), foo: conditionA, bar: conditionB()}">
    Hi
  </div>
</div>

Run blocks are the closest thing in Angular to the main method. A run block is the code which needs to run to kickstart the application. It is executed after all of the services have been configured and the injector has been created. Run blocks typically contain code which is hard to unit-test, and for this reason should be declared in isolated modules, so that they can be ignored in the unit-tests.

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265