Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
ng-class="{'active' : question.chosen == key}"

The above sets my class as active when question.chosen matches key. This means that $scope.question.chosen only has a single value.

In the even $scope.question.chosen has ["a","b","c"] how would I iterate through that with ng-class to match key?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You can try:

ng-class="{ 'active' : question.chosen.indexOf(key) >= 0 }"
share|improve this answer

You can have the ng-class object have keys as class names and values as functions that return booleans.

I set up a fiddle for you:

    <li ng-class="{'active': isActive('one')}">one</li>

http://jsfiddle.net/DrDyne/gZg7q/2/

Tell me if this helps :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.