New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The onChanges callback isn't called when updating the content of a bound object #6458
Comments
By default change detection system does reference comparison for objects - it doesn't do deep comparison by default as it would be too costly and would negatively impact performance. If you need to deep-observe object for changes you can do it explicitly using key-value differs. You can check implementation of the NgStyle directive for an example usage of a differ. |
Thanks very much, Pawel! That makes sense ;-) |
You tell "by default change detection ...". Is it possible to change this behavior in applications? Thanks! |
Just FYI, if you want to do the explicit checks yourself, you need to implement ngDoCheck() (which is called every change detection cycle) and do the checks inside that method. (This is what the NgStyle directive example shows, but the ngDoCheck() part might not be obvious.) |
I took inspiration from: - https://codesandbox.io/s/wn17j102v5 - angular/angular#6458 - https://github.com/angular/angular/blob/15cc85c54a9146c6d502cffad52a3c1a41fe4dcb/packages/common/src/directives/ng_style.ts - https://github.com/angular/angular/blob/15cc85c54a9146c6d502cffad52a3c1a41fe4dcb/packages/common/src/directives/ng_class.ts#L44 Maybe this can be implemented with a single differ, rather than the KeyValueDiffers, but I didn't find how to This calls `refine` on first render too, but that's okay, since it doesn't trigger an extra query This can be tested in the dev novel fixes #230
I took inspiration from: - https://codesandbox.io/s/wn17j102v5 - angular/angular#6458 - https://github.com/angular/angular/blob/15cc85c54a9146c6d502cffad52a3c1a41fe4dcb/packages/common/src/directives/ng_style.ts - https://github.com/angular/angular/blob/15cc85c54a9146c6d502cffad52a3c1a41fe4dcb/packages/common/src/directives/ng_class.ts#L44 Maybe this can be implemented with a single differ, rather than the KeyValueDiffers, but I didn't find how to This calls `refine` on first render too, but that's okay, since it doesn't trigger an extra query This can be tested in the dev novel fixes #230
I took inspiration from: - https://codesandbox.io/s/wn17j102v5 - angular/angular#6458 - https://github.com/angular/angular/blob/15cc85c54a9146c6d502cffad52a3c1a41fe4dcb/packages/common/src/directives/ng_style.ts - https://github.com/angular/angular/blob/15cc85c54a9146c6d502cffad52a3c1a41fe4dcb/packages/common/src/directives/ng_class.ts#L44 Maybe this can be implemented with a single differ, rather than the KeyValueDiffers, but I didn't find how to This calls `refine` on first render too, but that's okay, since it doesn't trigger an extra query This can be tested in the dev novel fixes #230
* chore(tslint): set up so stuff isn't red * docs(configure): example for a toggler with shallow change * fix(configure): make sure deep changes are also caught I took inspiration from: - https://codesandbox.io/s/wn17j102v5 - angular/angular#6458 - https://github.com/angular/angular/blob/15cc85c54a9146c6d502cffad52a3c1a41fe4dcb/packages/common/src/directives/ng_style.ts - https://github.com/angular/angular/blob/15cc85c54a9146c6d502cffad52a3c1a41fe4dcb/packages/common/src/directives/ng_class.ts#L44 Maybe this can be implemented with a single differ, rather than the KeyValueDiffers, but I didn't find how to This calls `refine` on first render too, but that's okay, since it doesn't trigger an extra query This can be tested in the dev novel fixes #230 * chore: fix linting * chore: revert adding stuff to the config * fix(configure): make it buildable!!! * docs(configure): add comment * test(configure): add test on diffing (rough)
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Hello,
Following a question on StackOverflow, I wonder why the
onChanges
is called when a bound object is updated (a new value) but not when the content of a bound object is updated.Here is the following use case:
Thanks for your help!
Thierry
The text was updated successfully, but these errors were encountered: