-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$evalAsync does not always get executed in the current $digest cycle (1.0.0rc8) #947
Comments
Sorry, this example is not right: It shows the old value because I use the wrong argument from the watch callback... |
Ok, here is a better example: http://jsfiddle.net/GGbzx/3/ A button increments a value on the $scope. When you click the button to increment the counter, the $evalAsync is no more executed in the same $digest. Tobias Everything works if you:
Tobias |
right the first fiddle incorrectly interpreted the order of arguments in the watch callback: http://jsfiddle.net/IgorMinar/GGbzx/4/ I'm looking at the second fiddle now |
this is not a bug. eval async does get executed, at the correct time, but the value you print is stale because it's a copy of the counter that is done in the watch fn. |
I'm actually happy that your example doesn't blow up - at first look I would expect it to fail with infinite digest error. The problem with your code is that your watch fn is not idempotent. The side-effect it has is the $evalAsync registration. This is a programming/design error in your code. Does your app suffer from the same issue or is there something else going on? |
I'm going close this bug. If you can repro it with idempotent watch fn then I'll be happy to reopen it and investigate further. |
Sorry for the late reply. Thanks for investigating this. |
Hi,
when I have a scope that contains a single $watch, which uses $evalAsync, then the $evalAsync does not get executed until the next $digest cycle, but not in the current $digest cycle.
Here is a jsfiddle to show the problem: http://jsfiddle.net/GGbzx/1/
When you type a character into the textbox, the $watch fires and logs the current value using $evalAsync to the console.
However, in this case, the value that is logged is not the current value of the input field, but the last value (e.g. type in "aaa", then the log only shows "aa".
Tobias
The text was updated successfully, but these errors were encountered: