문제

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