Webnet Webnet - 2 months ago 36
AngularJS Question

Angular expression if array contains

I'm trying to add a class to an element if a

jobSet
has not been selected for approval using expressions.

<li class="approvalUnit" ng-repeat="jobSet in dashboard.currentWork" ng-class="{-1:'approved'}[selectedForApproval.indexOf(jobSet)]">


This isn't exactly a fool proof method. Any suggestions on how I should do this?

Answer

You can accomplish this with a slightly different syntax:

ng-class="{'approved': selectedForApproval.indexOf(jobSet) === -1}"

Plnkr