Search code examples
angularjsangularjs-ng-repeatng-class

Set class value in Angularjs using repeat with multiple ng-if


Using Angularjs, I need to compare the value of $index to $parent.$index in a nested ng-repeat and set the value of the class according to this result. This is what I am currently trying-

<td ng-repeat="d in vm.users track by d._id"
  ng-class="{showBottomLine : less, showSides : more, showBottomSideLine : equals }">
    <div ng-if="$index < $parent.$index" ng-class="showBottomLine">less</div><!--ng-model="less"-->
    <div ng-if="$index  > $parent.$index" ng-class="showSides">more</div>
    <div ng-if="$index === $parent.$index" ng-class="showBottomSideLine">equals</div>
</td>

Solution

  • The syntax for ng-class is as follows:

    <p ng-class="{strike: deleted, bold: important, 'has-error': error}">Map Syntax Example</p>
    

    In your case

    $parent.$index" ng-class="{'showSides': $index == $parent.index}">