Question

I want to highlight the current user in a list of all users. My code looks like this.

<div class='user' ng-repeat='user in users'>
  <span class='name'>{{ user.displayName }}</span>
</div>

I have currentUser.id that I want to compare to user.id as I loop them through and perhaps add a class when the two match. I would like to do something like this in theory:

ng-class='highlight: if user.id == currentUser.id'
Was it helpful?

Solution

This should do it:

ng-class='{highlight: user == currentUser}'

OTHER TIPS

Gruff Bunny is correct.

Another way to do it that gets the logic a little more out of the DOM is to do the comparison in the controller or a directive and then assign the class with addClass.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top