10

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

Example:

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

Thank you!

2 Answers 2

16

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}}" 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you...is there a favorit way?
yes, I prefer the class attribute solution as it is much more readable.
1

You can use within html class:

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

for Angular use:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.