我无法在ng-class中运行函数。我已经复制了我一直在做的事情,你能找到错误吗?我想要做的是将粗体样式放在使用按钮选择的元素上。 Angular版本是1.3.4。评论'索引'永远不会在控制台中显示。
HTML:
<li ng-repeat="i in getNumber(numsteps) track by $index"
ng-class="isActive($index) ">
{{$index + 1}}
</li>
JavaScript的:
$scope.it = 0;
$scope.isActive = function(index) {
console.log('index');
if ($scope.it === index) {
return "bold";
}
};
$scope.next = function () {
$scope.it = $scope.it < $scope.dataNumsteps
? $scope.it + 1
: $scope.dataNumsteps;
console.log($scope.it);
};
$scope.after = function () {
$scope.it = $scope.it > 1 ? $scope.it - 1 : 1
console.log($scope.it);
};
答案 0 :(得分:1)
我认为您的实际问题是ng-class属性中的空格:ng-class="isActive($index) "
删除后,它可以运行:http://jsfiddle.net/7pn2un39/