To assign classes based on the ngRepeat index, I am using ng-init="myIndex = $index"
. With this setup, I can apply classes like color-0, color-1, color-2, etc. by using ng-class='"color-" + myindex'
.
Furthermore, I need to add a different class if an element is selected. For this purpose, I am using
ng-class="{'selected': element.selected}"
.
While both ngClass directives work independently, I am struggling to combine them in the same ngClass declaration.
I have tried variations like
ng-class="'color-' + myIndex, {'selected': element.selected}"
in various ways, but keep encountering the error:
Error: [$parse:syntax] Syntax Error: Token ',' is an unexpected token at column 19 of the expression ['color-' + myIndex, {'selected': element.selected}] starting at [, {'selected': element.selected}].