I'm wondering if it's possible to use a ternary expression in the ng-click attribute. I don't want to use a separate controller function if possible.
It's a two button toggle setup - I can get a simple toggle working, but don't want a second click of the "off" button to turn back on.
The ternary in ng-click does not work (note the ternary in ng-class does work):
<button
ng-click="allOn2==true ? allOn2 : !allOn2"
ng-class="allOn2==true ? 'btn-green-on' : 'btn-green-off'">
ON</button>
Here's a more complete jsfiddle: toggler
You are not doing anything with the ternary expression. For it to be useful, assign it:
{{ var1 }} {{ var2}}
<button
ng-click="var1 = (allOn2==true ? allOn2 : !allOn2)"
ng-class="{'btn-green-on':allOn2, 'btn-green-off' : !allOn2}">
ON</button>
I'm not sure how you can use ternary expressions for ng-class though...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With