gpt4 book ai didi

javascript - 没有工作功能 ng-class 和 ng-repeat

转载 作者:行者123 更新时间:2023-12-03 05:47:49 24 4
gpt4 key购买 nike

我无法在 ng 类中运行函数。我已经复制了我一直在做的事情,你能找出错误吗?我想要做的是将粗体样式放在使用按钮选择的元素上。 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);
};

最佳答案

我认为你的实际问题是 ng-class 属性中的空格: ng-class="isActive($index) "

删除后,它可以工作:http://jsfiddle.net/7pn2un39/

关于javascript - 没有工作功能 ng-class 和 ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40269156/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com