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

Outer change is stronger than the inner one when they are both changed and using one-way binding #14546

Closed
roymiloh opened this issue Apr 30, 2016 · 3 comments · Fixed by #14580
Assignees
Milestone

Comments

@roymiloh
Copy link

roymiloh commented Apr 30, 2016

Do you want to request a feature or report a bug?
Bug (?)

What is the current behavior?
I'm not sure if bug or by design, but when using one-way (<), if both the outer and inner scope have been changed, the outer is stronger, even if the inner's change happened after the outer one.
http://jsbin.com/zunoraquju/1/edit?html,js,output

What is the expected behavior?
I would simply expect that the last change is stronger, that's what happens till now with two-way (=). You can change my attached example to = and it will work.

What is the motivation / use case for changing the behavior?
Actually a common case - if the passed value is X I want to change it to be Y (in constructor / $onInit) and display it, but preserve the one-way so the outer scope won't get the update.

Which versions of Angular, and which browser / OS are affected by this issue? Did this work in previous versions of Angular? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.
1.5+

Other information (e.g. stacktraces, related issues, suggestions how to fix)
Relevant test (I would expect it to be misko)

@Narretz
Copy link
Contributor

Narretz commented May 9, 2016

If you use $onChanges, you can set the bound value in the component, because then one update cycle is complete. Setting in the constructor will never work, because the binding hasn't been done yet. I'm not sure if $onInit should work (it doesn't). @petebacondarwin wdyt?

@petebacondarwin
Copy link
Contributor

This does seem a little buggy. As @Narretz points out it will never work in the constructor. But I think we ought to get it to work elsewhere...

@petebacondarwin petebacondarwin modified the milestones: 1.6.x, Purgatory May 9, 2016
@petebacondarwin petebacondarwin self-assigned this May 9, 2016
@petebacondarwin
Copy link
Contributor

By the way, outer change is always going to be stronger than inner change. This is the meaning of one-way in this case. That being said, I think there is a problem with the initial change recording. It seems to call $onChanges on too many times at the start of the component life, which is overwriting what is set in $onInit.

petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue May 10, 2016
The watch handler was triggering on its first invocation, even though
its change had already been dealt with when setting up the binding.

Closes angular#14546
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue May 10, 2016
The watch handler was triggering on its first invocation, even though
its change had already been dealt with when setting up the binding.

Closes angular#14546
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue May 10, 2016
The watch handler was triggering on its first invocation, even though
its change had already been dealt with when setting up the binding.

Closes angular#14546
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue May 10, 2016
The watch handler was triggering on its first invocation, even though
its change had already been dealt with when setting up the binding.

Closes angular#14546
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue May 10, 2016
The watch handler was triggering on its first invocation, even though
its change had already been dealt with when setting up the binding.

Closes angular#14546
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue May 10, 2016
The watch handler was triggering on its first invocation, even though
its change had already been dealt with when setting up the binding.

Closes angular#14546
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue May 10, 2016
The watch handler was triggering on its first invocation, even though
its change had already been dealt with when setting up the binding.

Closes angular#14546
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue May 10, 2016
The watch handler was triggering on its first invocation, even though
its change had already been dealt with when setting up the binding.

Closes angular#14546
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue May 10, 2016
The watch handler was triggering on its first invocation, even though
its change had already been dealt with when setting up the binding.

Closes angular#14546
petebacondarwin added a commit that referenced this issue May 10, 2016
The watch handler was triggering on its first invocation, even though
its change had already been dealt with when setting up the binding.

Closes #14546
Closes #14580
petebacondarwin added a commit that referenced this issue May 10, 2016
The watch handler was triggering on its first invocation, even though
its change had already been dealt with when setting up the binding.

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

Successfully merging a pull request may close this issue.

3 participants