使用ng-class在AngularJS中传递类名

时间:2017-02-02 11:14:59

标签: javascript css angularjs ng-class

我有:

<tr ng-class="{{line.color}}" ng-repeat="line in gameRank | orderBy: sortType: sortReverse">
    <td>{{$index + 1}}</td>
    <td>{{line.username}}</td>
    <td>{{line.games}}</td>
    <td>{{line.winners}}</td>
</tr>

当我打开调试器时,我看到:

<tr class="ng-scope" ng-class="BLUE" ng-repeat="line in gameRank | orderBy: sortType: sortReverse">
    <td class="ng-binding">1</td>
    <td class="ng-binding">Admin</td>
    <td class="ng-binding">0</td>
    <td class="ng-binding">0</td>
</tr>

因此,我的班级BLUE未应用于我的元素。

我该如何解决?

1 个答案:

答案 0 :(得分:2)

应该是

<tr ng-class="line.color" ...>

而不是

<tr ng-class="{{line.color}}" ...>

JSFiddle demo