I can't wrap my head around this.
Here's a scenario: I am presenting a group of objects using ng-repeat
in this format:
<div ng-repeat="obj in objs">{{obj | json}}</div>
Now, I want to assign the class current
to one specific <div>
based on whether it corresponds to the "current object" defined by another scope variable called current
.
I attempted the following approach:
<div ng-repeat="obj in objs" ng-class="{current: 'obj == current'}">{{obj | json}}, current: {{obj == current}}</div>
The interesting part is: while the expression obj == current
is correctly analyzed within the div content and initially returns false for all instances when current
in the scope is null
, the class still gets assigned to each one, despite being contingent on the same logic.
Even if I update the value of current
to reference another object, the content inside the div adjusts accordingly and displays true
, but the class remains applied universally.
What am I overlooking here? Why is the class persisting even with a false evaluation?
To experiment with it: JSFiddle.