0

I'm trying to put a class on an input if it meets certain requirements and am having problems

it looks like so -

 ng-class="'isPartial': canPartial($index)" 

This is inside a repeat, the function it's referring to looks like so

$scope.canPartial = function(index) {
     var needsMet = _.reduce($scope.allAccounts[index].schools, function (memo, schools) {
  return memo + (schools.selected ? 1 : 0);
}, 0);
     console.log(needsMet);
return (needsMet === $scope.allAccounts[index].schools.length);
};

so it's using underscore.js to check if all its children are checked. I know the function works correct, however my issue is passing it as the condition for the ng-class. So if it returns true it will add the class. I'm getting a $parse.syntax error and I cannot seem to figuire out why because I se other examples of ng-class using a function. Perhaps it's because I'm trying to pass the $index, however it is inside a repeat, but I don't know if that causes an issue.

Any help would be much appreciated. Thanks!

1 Answer 1

1

Your ng-class expression is invalid.
Change your ng-class declaration in order to take an object as a value:

ng-class="{'isPartial': canPartial($index)}"

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

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.