简体   繁体   English

AngularJS,CSS:突出显示特定的表行

[英]AngularJS, CSS : Highlighting a particular table row

is there any way to highlight a particular table row? 有什么办法可以突出显示特定的表格行?

I have a table and a set if angular codes for example for example: 我有一个表和一组角度代码,例如:

angular.module('myApp', []).controller('myTest', function($scope) {

 var data = [];
 for(var i = 0; i < 10; i++) {
      data[i] = i;
 }
 $scope.data = data; 

});

HTML: HTML:

<table ng-app="myApp" ng-controller="myTest">
 <tr ng-repeat="x in data">
      <td > {{ x }} </td>
 </tr>
</table>

http://jsfiddle.net/omarjmh/Lvc0u55v/1895/ http://jsfiddle.net/omarjmh/Lvc0u55v/1895/

Is there anyway to do it like 反正有做吗

if x is equal to 1 then css:highlight tr: blue ? 如果x等于1,则css:highlight tr:blue?

Thanks! 谢谢!

you can use $even and $odd for this. 您可以为此使用$ even和$ odd。

 angular.module('myApp', []).controller('myTest', function($scope) { var data = []; for(var i = 0; i < 10; i++) { data[i] = i; } $scope.data = data; }); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app = "myApp"> <div ng-controller="myTest"> <table > <tr ng-repeat="x in data" ng-style="{'background-color': ($even ? 'green' : 'red')}"> <td > {{ x }} </td> </tr> </table> </div> </div> 

使用ngStyle

tr ng-repeat="x in data" ng-style="{'background-color': (x === 1 ? 'blue' : 'white')}"

You can achieve it by using CSS, 您可以使用CSS来实现,

tr:nth-child(even) {
    background-color: #000000;
}

even/odd both works. 偶数/奇数都可行。

Or with angular, 或有角度的

You should be using the angular directives ngClassEven and ngClassOdd for this. 您应该为此使用角度指令ngClassEven和ngClassOdd。

Have a look at the documentation section for how to use them 查看文档部分,了解如何使用它们

http://docs.angularjs.org/api/ng.directive:ngClassEven http://docs.angularjs.org/api/ng.directive:ngClassEven

http://docs.angularjs.org/api/ng.directive:ngClassOdd http://docs.angularjs.org/api/ng.directive:ngClassOdd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM