Arabela Rojas
Arabela Rojas

Reputation: 1

Behavior with ng-show and ng-hide in angular

This is my code: 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;
  };
};

this work's fine.

the problem is when another button is clicked ,the previous click stay active so the cross don't change.

first button , when clicked

Now another button is clicked , and previous is active yet

Idk how to change the 'active' , any other solution ?

Upvotes: 0

Views: 88

Answers (1)

kabaehr
kabaehr

Reputation: 1040

Just guessing what you want to achieve, but you should try this:

<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>

Upvotes: 1

Related Questions