0

I want to evaluate multiple expressions, but the class applied will be the same. Here's an example...

<tr ng-class="{'highlight' : Expression1 || Expression2 || Expression3}">

If any of the expressions are true, it will apply the highlight class. I have tried a few versions, but I'm not sure if this is the correct approach.

<tr ng-class="{'highlight' : Expression1, 'highlight' : Expression2 }">
<tr ng-class="[{'highlight' : Expression1, 'highlight' : Expression2 }]">

None of these seem to work, and all the example I have seen apply a different class to each evaluation.

Christian Phillips
  • 18,399
  • 8
  • 53
  • 82

3 Answers3

2

This is just fine and I believe the correct way to do it.

<tr ng-class="{'highlight' : Expression1 || Expression2 || Expression3}">
Mathew Berg
  • 28,625
  • 11
  • 69
  • 90
  • I have no idea why it didn't work previously, but this is now working - I can only assume the css or javascript file was cached! Thanks anyway. – Christian Phillips Oct 08 '15 at 15:33
  • Potentially :) if you're using chrome, open up the dev tools (f12) click on the cog, and then select disable cache (Should be in the top left). Also... spare an upvote? – Mathew Berg Oct 08 '15 at 16:04
0

Would this be of use?

<!-- example with string syntax -->
<!-- use the type variable as a class -->
<div class="item ng-class:type;">Stuff Goes Here</div>

<!-- example with string syntax -->
<!-- use the styleOne and styleTwo variables as classes -->
<div class="item ng-class:[styleOne, styleTwo];">Stuff Goes Here</div>

<!-- example with evaluated data -->
<!-- add the text-error class if wrong is true -->
<div class="item ng-class:{ 'text-error': wrong };">Stuff Goes Here</div>

Taken from: The many ways to use ng-class

Jelmer
  • 949
  • 3
  • 10
  • 23
0

Check the version of angular library you are using.

Shamal Perera
  • 1,611
  • 1
  • 18
  • 21