Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Use angular.equals() to check if one way bindings changed #14827

Closed
adamreisnz opened this issue Jun 26, 2016 · 3 comments
Closed

Use angular.equals() to check if one way bindings changed #14827

adamreisnz opened this issue Jun 26, 2016 · 3 comments

Comments

@adamreisnz
Copy link

adamreisnz commented Jun 26, 2016

What is the current behavior?
When a one-way bound array reference changes, even if the currentValue and previousValue pass the equality check of angular.equals(), it is still registered as a change.

This is causing my $onChanges even listener to fire even though the current and previous values are of the same type and of the exact same contents/properties.

I am not sure if this is intentional behaviour or a bug.

What is the expected behavior?
That this kind of change would not trigger the $onChanges event for that particular property, because, other than the reference to another object, nothing has in fact changed (array content wise).

What is the motivation / use case for changing the behavior?
My current work around is that I have to manually check the current/previous value with angular.equals() to make sure I don't mark the form dirty for no reason (it is used in a form control directive). This feels a bit redundant.

Which versions of Angular
Angular 1.5.6

@gkalpak
Copy link
Member

gkalpak commented Jun 26, 2016

This is working as intended. For more context see #14378.

tl;dr
Deep-watching would be too expensive and inconsistent with Angular 2.

@gkalpak gkalpak closed this as completed Jun 26, 2016
@gkalpak
Copy link
Member

gkalpak commented Jun 26, 2016

BTW, the possibility to add supporting for $watchCollection to one-way bindings is discussed in #14039 (as you already know 😉). It's not equivalent to deep-watching, but it is deeper than watching by reference.

@adamreisnz
Copy link
Author

Yeah, I figured this would be the case. Ok, I'll use angular.equals() as a workaround for now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants