javascript - Angular ,ng 类,内部有重复函数

标签 javascript angularjs

如果输入满足某些要求并且遇到问题,我会尝试在输入上放置一个类

看起来是这样的 -

 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/

相关文章:

javascript - 如何从 Steam 中的其他个人资料获取愿望单数据?

javascript - 没有类的 React 有状态组件

javascript - Chrome 选项卡内存不断增长,堆大小保持不变

javascript - 在 AngularJS 上将文本渲染为 HTML

javascript - AngularJS 循环遍历数组(一系列数字)

javascript - 在 Javascript 上检查互联网连接

javascript - 使用 HTMLWebpackPlugin 时如何通过 webpack 加载图片?

javascript - 快速路线和 Controller

javascript - AngularJS UI-Router父级

javascript - "Error: <path> attribute d: Expected number, "MNaN、NaNLNaN、NaNL…". "D3 错误