[Fixed]-How to change the color of table rows once ng-repeat executed


You can do this using ngClassEven and ngClassOdd directives built into angular, to be used with ng-repeat. For example:

<tr ng-repeat="(k,v) in final_data.histories" ng-class-even="'my-even-class'" ng-class-odd="'my-odd-class'">

Then you simply need to add the my-even-class and my-odd-class classes to your css, and style as you want.

Update: If you have more complex requirements for styling (eg, not just based on whether a row is odd or even, you can apply conditional classes based on any logic you want using ng-class. Say you wanted to style every row whose item has a field myField that was greater than 5.

<div ng-class="{'my-class' : v.myField > 5}"></div>

This will only put the my-class class on the items that adhere to the condition, and then can be styled as you wish.

Leave a comment