Angularjs 在ng repeat中设置DIV的类

Angularjs 在ng repeat中设置DIV的类,angularjs,Angularjs,我有下一个HTML代码: <div class="small-3 column cell" ng-repeat="cell in line track by $index"> {{ cell }} </div> {{cell}} 如何基于{cell}}值为DIV元素添加其他类。例如,“空”表示单元格=0,而“满”表示单元格!=0? <div class="..." ng-repeat="cell in line" ng-class="

我有下一个HTML代码:

<div class="small-3 column cell" 
     ng-repeat="cell in line track by $index">

     {{ cell }}

</div>

{{cell}}
如何基于{cell}}值为DIV元素添加其他类。例如,“空”表示单元格=0,而“满”表示单元格!=0?


<div class="..." ng-repeat="cell in line" ng-class="{empty:(cell==0), full:(cell!=0)}">
    ...
</div>
...
可以进一步简化为

<div class="..." ng-repeat="cell in line" ng-class="(cell==0) ? 'empty' : 'full'">
    ...
</div>

...
您可以使用支持的任何东西。最适合你所描述的

如果您需要的逻辑比使用ng类所能做的更复杂,那么您可以始终为此场景创建一个控制器

<div class="small-3 column cell" ng-controller="MyCtrl"
     ng-repeat="cell in line track by $index">

     <div class="{{getClass()}}"></div>

</div>

function MyCtrl($scope) {
   $scope.getClass = function() {
      if($cell == whatever) return "whatever";
      return "nothing";
   }
}

函数MyCtrl($scope){
$scope.getClass=function(){
if($cell==whater)返回“whater”;
返回“无”;
}
}
请参阅。