【发布时间】:2014-12-11 20:54:35
【问题描述】:
我有一个使用 AngularJS ngRpeat 生成行的表:
<tr ng-repeat="player in division">
<td>{{player.name}}</td>
<td>{{player.score}}</td>
</tr>
数组看起来有点像这样:
$scope.divison = [
{
name: "John Doe",
score: "10",
goingUp : true
},
{
name: "Bob Marley",
score: "20"
}
];
现在,如果我想根据特定的ng-repeat 将ng-class 应用于表格行怎么办?尽管这可能可行,但我会认为:
<tr ng-repeat="player in division" ng-class="'goingUp' : player.goingUp">
<td>{{player.name}}</td>
<td>{{player.score}}</td>
</tr>
唉,这行不通。可能是因为 ng-class 不在该重复元素内。我怎样才能让它工作呢?
【问题讨论】:
-
试试:
ngclass="(player.goingUp) ? 'goingUp' : ''" -
ng-class="{'goingUp' : player.goingUp}"
-
@Second2None 谢谢,我只是错过了那些括号。如果您想将其作为答案发布,我将接受它作为正确的语法和最简单的方法。
-
这是一个错误。 github.com/angular/angular.js/issues/2368 尚不清楚该修复是否在当前版本中。
标签: javascript html arrays angularjs