-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$scope.$watch doesn't see DOM changes done in current $digest cycle, but sees them in next cycle #10522
Comments
@olexme putting aside behavior change between 1.2.x and 1.3.x you should never ever watch DOM properties - accessing DOM in the detection function of the $watch is a big perf no-no. I'm not sure what is your real-life use-case but I don't think we want to investigate / fix the issue you've exposed as this is not a use-case we want to promote in AngularJS. If you could talk about a real-life problem you are trying to solve, maybe someone will be able to provide a more AngularJS-like solution. |
Thanks for that comment. I added this issue cause I didn't find explicit breaking change note in migration guide |
Without looking deep into it, it must be a change to
So, technically speaking, it is a change that happened in @olexme: It is always a good idea to check the Changelog for breaking changes when upgrading to a newer version. |
Hm...looking at it again, it seems that the Changelog notice is somewhat misleading: |
Yeh, OK, it sounds like a documented breaking change. Anyway, as stated above, this is really a corner case with the behaviour that definitively shouldn't be encouraged. |
Specifically it doesn't see changes made for class attribute by ng-class directive.
The issue occures for AngularJS v1.3.7, for Angular 1.2.26 is ok.
Below is easy to analyse fure Angular plunker example, with $watch based on function checking class attribute changes in each digest cycle (or more times per digest).
Steps to reproduce the issue:
http://plnkr.co/edit/sTjGayZnG8ti6X6LgElZ?p=preview
The text was updated successfully, but these errors were encountered: