如果输入满足某些要求并且遇到问题,我会尝试在输入上放置一个类
看起来是这样的 -
ng-class="'isPartial': canPartial($index)"
这是在重复中,它引用的函数看起来像这样
$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);
};
因此它使用 underscore.js 来检查其所有子项是否都已检查。我知道该函数工作正常,但我的问题是将其作为 ng 类的条件传递。所以如果它返回 true 它将添加该类。我收到 $parse.syntax 错误,我似乎无法弄清楚为什么,因为我看到了使用函数的 ng-class 的其他示例。也许是因为我试图传递 $index,但它在重复中,但我不知道这是否会导致问题。
任何帮助将不胜感激。谢谢!
最佳答案
你的ng-class
expression无效。
更改您的ng-class
声明以便将对象作为值:
ng-class="{'isPartial': canPartial($index)}"
关于javascript - Angular ,ng 类,内部有重复函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26935059/