Seyong Cho Seyong Cho - 2 years ago 150
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"
ng-class="{'selected',$index == $parent.glossarySection}">

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 Source

There is a syntax error: replace , to :.

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download