简体   繁体   中英

Change Buttons when Clicked

Below is my HTML code with Bootstrap and Angular:

   <button class="btn btn-secondary btn-sm" ng-click="buy(player)">{{history.indexOf(player)>=0?'REMOVE':'SELECT'}}</button>

When i click the button, the wording of the button changes from 'SELECT' to 'REMOVE'. However, what i want is the colour of the button to change so that it is the default colour when on 'SELECT' but the red "btn-danger" class when 'REMOVE'.

Is this possible?

Sure! And it's really simple.

 <button class="btn btn-secondary btn-sm" ng-class="{'btn-danger': history.indexOf(player) >= 0 }" ng-click="buy(player)">{{history.indexOf(player)>=0?'REMOVE':'SELECT'}}</button>

Note ng-class directive added to the button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM