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

One-time binding deep-copies an object #7907

Closed
mhelvens opened this issue Jun 19, 2014 · 5 comments
Closed

One-time binding deep-copies an object #7907

mhelvens opened this issue Jun 19, 2014 · 5 comments

Comments

@mhelvens
Copy link

I have noticed that one-time binding with :: always wants to deep-copy objects in an expression, whereas normal binding will simply store and compare a reference.

Minimal example: http://jsfiddle.net/mhelvens/PXdkK/1/

This example demonstrates the inconsistent behavior by binding to an object that holds a reference to a $scope. The one-time binding prompts an ng:cpws error, indicating that a deep copy is being made.

I would prefer the traditional behavior for various reasons. But in any case, I assume that this inconsistency was not deliberate.

@mhelvens mhelvens changed the title One-time binding always deep-copies an object One-time binding deep-copies an object Jun 19, 2014
@Narretz Narretz added this to the 1.3.0 milestone Jun 23, 2014
@rodyhaddad rodyhaddad modified the milestones: 1.3.0-beta.14, 1.3.0 Jun 23, 2014
@rodyhaddad
Copy link
Contributor

This would be fixed by #7700

@mhelvens
Copy link
Author

Indeed. Out of curiosity, why was that line included in the first place? I'm not experiencing any problems after removing it.

@lgalfaso
Copy link
Contributor

Indeed
https://github.com/angular/angular.js/pull/7700/files#diff-780de070ede30180f6aedb6c5f7d57caL1059.
Out of curiosity, why was that line included in the first place? I'm not
experiencing any problems after removing it.

If there is an interpolated expression with multiple parts, one of them is
an object and the other is not a one-time bonded expression, then the
former is transformed to json. Now, if you change the former in-place (this
is you change some property of the object without changing the object
instance), then, when you change the second expression, the first
expression is interpolated once again and the updated json is displayed.
#7700 uses watchGroup that fixes this issue without he need for a copy.

@mhelvens
Copy link
Author

Awesome. Thanks!

@Narretz
Copy link
Contributor

Narretz commented Jul 15, 2014

Fixed by 86d55c1

@Narretz Narretz closed this as completed Jul 15, 2014
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

6 participants