Seyong Cho Seyong Cho - 6 months ago 49
AngularJS Question

AngularJS ng-class not working in ng-repeat with $index

I have a list created with ng-repeat that works for everything except for adding the ng-class on condition.

<div ng-repeat="glossary in glossarySections"
class="alphabet"
ng-click="glossaryGoToSection($index)"
ng-class="{'selected',$index == $parent.glossarySection}">
{{glossary.name}}
</div>


ng-click works, and it creates the DOM the way I expect it to, but it doesn't add the 'selected' class for the alphabet currently shown.

Is there something that I am missing in this syntax?

Joy Joy
Answer

There is a syntax error: replace , to :.

Modify to ng-class="{'selected': $index == $parent.glossarySection}">.

Comments