css:
.color-red{background-color:red;}
.color-blue{background-color:blue;}
.color-yellow{background-color:yellow;}
.color-green{background-color:green;}
.color-yanc{background-color:cyan;}
html:
<body ng-app="myApp">
<div ng-controller="myCtrl">
<p>方式一:</p>
<ul>
<li ng-repeat="item in data" class="{{item.index==0?'color-red':'color-blue'}}">{{item.name}}</li>
</ul>
<p>方式二(分页且当后台数据以一页一页方式传过来的时候,会失效):</p>
<ul>
<li ng-repeat="item in data" ng-class="{10:'color-yellow',20:'color-green',30:'color-blue'}[{{item.num}}]">{{item.name}}</li>
</ul>
<p>方式三(分页时不影响):</p>
<ul>
<li ng-repeat="item in data" ng-class="{'color-yellow':item.num==10,'color-green':item.num==20,'color-blue':item.num==30,}">{{item.name}}</li>
</ul>
</div>
</body>
数据:
<script src="https://cdn.bootcss.com/angular.js/1.4.4/angular.js"></script>
<script>
angular.module("myApp",[]).controller("myCtrl",function($scope)
{
$scope.data = [
{
name :"小明",
sex :"男",
index :0,
num :10
},
{
name :"小红",
sex :"男",
index :0,
num :20
},
{
name :"小花",
sex :"女",
index :1,
num :30
}
]
})
</script>
.color-red{background-color:red;}
.color-blue{background-color:blue;}
.color-yellow{background-color:yellow;}
.color-green{background-color:green;}
.color-yanc{background-color:cyan;}
html:
<body ng-app="myApp">
<div ng-controller="myCtrl">
<p>方式一:</p>
<ul>
<li ng-repeat="item in data" class="{{item.index==0?'color-red':'color-blue'}}">{{item.name}}</li>
</ul>
<p>方式二(分页且当后台数据以一页一页方式传过来的时候,会失效):</p>
<ul>
<li ng-repeat="item in data" ng-class="{10:'color-yellow',20:'color-green',30:'color-blue'}[{{item.num}}]">{{item.name}}</li>
</ul>
<p>方式三(分页时不影响):</p>
<ul>
<li ng-repeat="item in data" ng-class="{'color-yellow':item.num==10,'color-green':item.num==20,'color-blue':item.num==30,}">{{item.name}}</li>
</ul>
</div>
</body>
数据:
<script src="https://cdn.bootcss.com/angular.js/1.4.4/angular.js"></script>
<script>
angular.module("myApp",[]).controller("myCtrl",function($scope)
{
$scope.data = [
{
name :"小明",
sex :"男",
index :0,
num :10
},
{
name :"小红",
sex :"男",
index :0,
num :20
},
{
name :"小花",
sex :"女",
index :1,
num :30
}
]
})
</script>