Frage

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'
War es hilfreich?

Lösung

This should do it:

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

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top