Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use ng-repeat index as class name?

Tags:

angularjs

Is it possible to use the $index of ng-repeat in the class name?

Example:

ng-class="{'hand-' + $index: true}"

Thank you!

like image 954
nofear87 Avatar asked Aug 15 '14 10:08

nofear87


2 Answers

You can use it like this:

ng-class="['hand-' + $index]"

Additionally, you can use the class attribute to interpolate the class value

class="hand-{{$index}}"
like image 160
ryeballar Avatar answered Sep 18 '22 17:09

ryeballar


You can use within html class:

class="list-{{$index}}"

for Angular use:

ng-class="['hand-' + $index]"
like image 29
Ashish Gupta Avatar answered Sep 21 '22 17:09

Ashish Gupta