Skip to main content
made it clearer with clarifications from comments
Source Link
ryanyuyu
  • 6.5k
  • 11
  • 52
  • 56

I have two buttons. One is "State1"states for a button, "State1" and another is "State2""State2".

In the beginning, it is in "State2" buttonIt defaults to "State2". ThenWhen I click "State2"the button, it toggletoggles to "State1" button"State1".

 
When I want to click out of "State1"anywhere outside the button, thenI need it willto change from "State1" button"State1" back to "State2" button"State2". How do I do? This is my code:

<div ng-click="Ctrl.Check = !Ctrl.Check">
            <a ng-class="{'btn-danger': !Ctrl.Check, 'btn-default': Ctrl.Check }" >
                {{ Ctrl.Check ? 'State1' : 'State2' }}
            </a>
</div>

I have two buttons. One is "State1" and another is "State2".

In the beginning, it is in "State2" button. Then I click "State2" button, it toggle to "State1" button.

  I want to click out of "State1" button, then it will change from "State1" button to "State2" button. How do I do?

<div ng-click="Ctrl.Check = !Ctrl.Check">
            <a ng-class="{'btn-danger': !Ctrl.Check, 'btn-default': Ctrl.Check }" >
                {{ Ctrl.Check ? 'State1' : 'State2' }}
            </a>
</div>

I have two states for a button, "State1" and "State2".

It defaults to "State2". When I click the button, it toggles to "State1".
When I click anywhere outside the button, I need it to change from "State1" back to "State2". This is my code:

<div ng-click="Ctrl.Check = !Ctrl.Check">
            <a ng-class="{'btn-danger': !Ctrl.Check, 'btn-default': Ctrl.Check }" >
                {{ Ctrl.Check ? 'State1' : 'State2' }}
            </a>
</div>
Source Link
AngularFan
  • 33
  • 1
  • 2
  • 9

Toggle button when click out of button

I have two buttons. One is "State1" and another is "State2".

In the beginning, it is in "State2" button. Then I click "State2" button, it toggle to "State1" button.

I want to click out of "State1" button, then it will change from "State1" button to "State2" button. How do I do?

<div ng-click="Ctrl.Check = !Ctrl.Check">
            <a ng-class="{'btn-danger': !Ctrl.Check, 'btn-default': Ctrl.Check }" >
                {{ Ctrl.Check ? 'State1' : 'State2' }}
            </a>
</div>