2

I can't make this work, any idea what I'm missing?

<li ng-repeat="person in persons" ng-class="selected:currentPersonID===person.id">

Displaying currentPersonID and person.id shows the appropriate data, but I get an Angular parse error with that expression.

2 Answers 2

6

You should write

<li ng-repeat="person in persons" ng-class="{'selected': currentPersonID === person.id}">

The ngClassdocs says:

<ANY ng-class="{expression}">
   ...
</ANY>

The curly braces are necessary there.

The single quotes are documented in a comment on the same page (I know, should be on the official docs, but...)

Sign up to request clarification or add additional context in comments.

3 Comments

Please expand a little more on why your solution is correct while the op's is not.
@arne I wish I could explain more, but its really straightforward. The curly braces are on docs while the single quote are documented in a comment (yeah, I know) on the same documentation.
You could have written exactly that in your answer, together with a link to the documentation.
1

The ngClass directive accepts a map of class names to boolean values. You 're missing the curly braces:

<li ng-repeat="person in persons" ng-class="{selected : currentPersonID === 
person.id}">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.