You can change watched value in $watch
if you know what you're doing :)
#4583
ADTC
started this conversation in
2. Show and tell
Replies: 1 comment
-
$effect would be more like an effect to respond to all dependencies, and it has built in prevention of simple endless loops. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The
$watch
functionality is quite similar touseEffect
in React so I'm able to apply similar principles.One thing the docs note is this stern warning:
I'm supposing this applies to watching simple values as well, as changing them seems to trigger the callback again.
However, in certain situations, this could actually turn out to be useful.
In this case, if there's some error state, the watched value is "reset" and the effect is cancelled (when run again) on the empty value. This would not cause an infinite loop, but it is a clever trick to respond only to non-empty values.
Sidenote: We should probably mention in docs that the first argument of
$watch
should be a string referencing the property, not the property itself. That was a gotcha for me.Beta Was this translation helpful? Give feedback.
All reactions