-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Cloned nodes store ref to original on originalNode, inheritedData checks... #2534
Conversation
…cks if element isClone and if so checks data on originalNode
This is also related to this bug: #1805. @colinkahn , I think a better solution is to make a copy of the data attached to a node when we clone it. That way, we don't have to try to track whether nodes are cloned and more easily handles the situation where the original node gets deleted. |
Moreover, I think this version is dangerous in that it allows your cloned node to access controllers that are inherited by the original node, which doesn't make sense. If you move a node to a new point in the DOM then its inheritedData should change accordingly. |
As of 1.4 jQuery provides a parameter to cloneWithDataAndEvents. I guess we need something like this. I am not sure about the events though since they would need to be attached to a suitable scope. |
This is further complicated by the fact that if you are cloning a node and creating a new scope for it then you need to wire up the controller with this new scope, rather than use the original controller (or even a clone of it). From looking at the code, the following Angular specific data is added to nodes:
From looking at above, it seems that actually the |
Just to clarify what scope should be bound to a cloned node's controller. I think that if the element has been cloned for transclusion then its scope should be the transclusion scope. Is that correct? |
By the way, this is all really about transclusion, not any particular directive. |
@colinkahn & @IgorMinar - not made much progress with this as it is highly convoluted inside the compiler. Any further ideas? |
@petebacondarwin thanks for taking a look and providing these details. Overall this definitely raises a few questions for me. Regarding the point about inheriting data when a cloned element changes parents, I agree that this makes my solution less than optimal. My current solution to work around this is similar to what you had suggested, which is basically copying the data from the original to the cloned element (in coffeescript):
I guess where it gets confusing is when you start mentioning cloned controllers. Currently, if I have a directive that behaves like ngRepeat but has a controller and I use my copyData on it, then all the clones will share the original controller (essentially the controller for the "group" of stamped out clones). IMO this makes sense, having each cloned element get its own new copy of the directives controller means losing the connection between all of them. If clone-by-clone logic needs to happen then the clone can access methods on the "group" controller, or do something similar to ngSwitch, registering themselves on that controller to be used later. I think that would greatly simplify solving the problem, but of course, this is just my opinion on how all of this should work. |
I have commented on the issue. Could you better explain what the issue is and what you think should happen. As it stands right now having a controller on ngRepeat makes no sense since it is unclear what should happen if controller goes to zero and with which element should the controller be associated with. |
Let's close this PR and work on the issue toward a final solution. |
... if element isClone and if so checks data on originalNode
For issue #2533