Skip to content
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

draggable binding interferes with $parent #51

Closed
cuu508 opened this issue May 6, 2013 · 2 comments
Closed

draggable binding interferes with $parent #51

cuu508 opened this issue May 6, 2013 · 2 comments

Comments

@cuu508
Copy link

cuu508 commented May 6, 2013

Looks like $parent context variable is incorrect inside elements that use the draggable binding. Example fiddle:

http://jsfiddle.net/pjbWC/5/

This fiddle prints out $data and $parent values for array elements, they turn out to be equal, which I didn't expect.

In source of the binding, update() method, there's this line:

var templateOptions = prepareTemplateOptions(valueAccessor, "data");

The issue goes away if I change "data" to something else:

var templateOptions = prepareTemplateOptions(valueAccessor, "draggable");

I don't understand this well at all, so not sure if this is correct fix, and what side-effects it may have.

@rniemeyer
Copy link
Owner

@cuu508 - hello. The draggable binding is a wrapper to the template binding, so it creates a new context based on whatever is passed in. In your fiddle, it just happens that you are passing in the current data ($data), so both $data and $parent will be the same value. I can understand how this would not be less than obvious in this case, but I hope that this helps explain the behavior.

It would be similar to something like: http://jsfiddle.net/rniemeyer/pjbWC/6/

@cuu508
Copy link
Author

cuu508 commented May 8, 2013

Thanks for explanation, now this behaviour makes sense and I see it works as intended.

@cuu508 cuu508 closed this as completed May 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants