这是我的代码:
的HTML:
<div ng-controller="ButtonController">
<button class=" circle-white btn btn-collapse-custom" ng-click="collapse(1); toggleBtn()">
<i ng-show="imgbtn" class="fa fa-chevron-down"></i>
<i ng-hide="imgbtn" class="fa fa-times"></i>
</button>
</div>
js:
'use strict'
module.exports = function($scope , $rootScope ){
$scope.imgbtn = true;
$scope.toggleBtn = function() {
$scope.imgbtn = $scope.imgbtn === false ? true: false;
};
};
这项工作很好。
问题是单击另一个按钮时,前一个单击保持活动状态,因此十字不会改变。
first button , when clicked
Now another button is clicked , and previous is active yet
IDK如何更改“主动”,还有其他解决方案?
最佳答案
只是猜测要实现的目标,但是您应该尝试以下操作:
<div ng-controller="ButtonController">
<button class=" circle-white btn btn-collapse-custom" ng-click="collapse(1); imbtn = !imbtn">
<i ng-class="{'fa fa-chevron-down': imbtn, 'fa fa-times': !imbtn}">
</i>
</button>
</div>
关于javascript - Angular 中ng-show和ng-hide的行为,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36484659/