toggle an equation
#2687
-
how would I toggle an addition/subtraction? I was trying something like:
I want to see the x-text toggle from 20 to 25. This isn't working but I think it expresses what I'm trying to do. |
Beta Was this translation helpful? Give feedback.
Answered by
SimoTod
Feb 19, 2022
Replies: 1 comment 3 replies
-
The closest thing to your initial example is probably <div x-data="{ value: 20, diff: 5, add: false }">
<button @click="add = ! add" x-text="value + (add ? diff : 0)"></button>
</div> In a nutshell, you need a control flag, you can't use the variable holding the value as a boolean. If you need to update <div x-data="{ value: 20, diff: 5, added: false }">
<button @click="value += (added ? (diff * -1) : diff); added = ! added" x-text="value"></button>
</div> |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
fredbouin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The closest thing to your initial example is probably
In a nutshell, you need a control flag, you can't use the variable holding the value as a boolean.
If you need to update
value
, instead of just showing it, you can use something like