Search code examples
javascriptangularjsangularjs-ng-repeatng-class

Verify $index and set a style


Im trying to highlight a table line, but its hard to translate to angular js inside of the directive. Check the pseudo code:

if(highlight.indexOf($index) != -1) set .highlight css class

This is an example of my code:

$scope.highlight  = [0,2,3]
.highlight {
  color: red;
}
<table class="ui celled table">
  <thead>
    <tr>
      <th>AAA</th>
      <th>BBB</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="a in as track by $index"> <!-- The ng-class needs to be here, but where should i do the verification? -->
      <td>{{a}}</td>
      <td>{{b[$index]}}</td>
    </tr>
  </tbody>
</table>


Solution

  • Use ng-class after the ng-repeat:

    <tr ng-repeat="a in as track by $index" ng-class="{highlight: highlight.indexOf($index) > -1}">