Вопрос

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'
Это было полезно?

Решение

This should do it:

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

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top