使用ng-class的AngularJS切换类
我正在尝试使用切换元素的类 ng-class <button class="btn"> <i ng-class="{(isAutoScroll()) ? 'icon-autoscroll' : 'icon-autoscroll-disabled'}"></i> </button> isAutoScroll(): $scope.isAutoScroll = function() { $scope.autoScroll = ($scope.autoScroll) ? false : true; return $scope.autoScroll; } 基本上,如果$scope.autoScroll为true,我希望ng-class是icon-autoscroll,如果为false,我希望它为icon-autoscroll-disabled 我现在无法使用,并且在控制台中产生此错误 Error: Lexer Error: Unexpected next character at columns 18-18 [?] in expression [{(isAutoScroll()) ? 'icon-autoscroll' : 'icon-autoscroll-disabled'}]. 如何正确执行此操作? 编辑 解决方案1 :(已过时) <button …