CodeToad CodeToad - 1 year ago 97
AngularJS Question

angular: toggle text of button based on boolean value in model

what is a simple way to change the text in a button element based on boolean value?

pseudo code:

<button> some text OR some other text </button>

I read this: Angularjs if-then-else construction in expression

and this regarding ng-switch:

neither seems to work using bool value from model

Answer Source

I guess it depends on what the text is that you are trying to show. If you have control over what the text is in the controller, you can bind the text to a scope variable and set it in the controller so you don't have to put any logic in the view. Something like:


Otherwise, you can use an ng-if or ng-show on the boolean condition.

<button ng-show="someBoolValue">some text</button>
<button ng-show="!someBoolValue">some other text</button>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download