[英]No working function ng-class with ng-repeat
I cannot run function in the ng-class. 我无法在ng类中运行函数。 I've copied what I've been doing, could you look for the error?
我已经复制了我一直在做的事情,您可以查找错误吗? What I want to do is to put the bold style on the element selected with a button.
我要做的是将粗体样式放置在通过按钮选择的元素上。 The Angular version is 1.3.4.
Angular版本是1.3.4。 Comment 'index' never shows in the console.
注释“索引”从不显示在控制台中。
Html: HTML:
<li ng-repeat="i in getNumber(numsteps) track by $index"
ng-class="isActive($index) ">
{{$index + 1}}
</li>
JavaScript: 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);
};
I think your actual problem is the space in your ng-class attribute: ng-class="isActive($index) "
我认为您的实际问题是ng-class属性中的空格:
ng-class="isActive($index) "
When removed, it works: http://jsfiddle.net/7pn2un39/ 删除后,它会起作用: http : //jsfiddle.net/7pn2un39/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.