Search code examples
angularjsng-class

use of ng-repeat with ng-class and $index


i need different classes to be used for each iteration, following code.

Edit: the index is within the li

<li class="table-view-cell bg_{{$index}}" ng-repeat="agenda in agendas">
        <span class="cell">
            <a data-href="#/agendas/{{agenda.id}}" ng-click="detail($event, agenda.id)">
                <span class="type">{{agenda.date}}</span>
            </a>
        </span>
    </li>

also Why do we need ng-class, could I not use simple class here?


Solution

  • Try to replace ng-classs with just class, and add track by $index in your ng-repeat.

    Or skip track by. Not sure what you are trying to do but, this should get you going: http://jsfiddle.net/clto/HB7LU/8072/