Within my angular service, I have two objects with a property named nodes
that I want to point to the same array. However, when I make changes to the nodes in one object, it does not reflect on the other. Here is how I am attempting to achieve this:
objectOne.nodes = [o1, o2, o3];
objectTwo.nodes = [];
angular.forEach(objectOne.nodes, function(n){
objectTwo.nodes.push(n); // Some logic assigns nodes from objectOne to objectTwo
})
I expect changes made to objectTwo.nodes[i]
to be reflected in objectOne.nodes[j]
, given that i and j are indices of the same node in the two different objects (assuming the order may differ). Unfortunately, this does not seem to work as intended. Is there an error in the way I push nodes into objectTwo
?
For context, I am modifying the objectTwo node directly within the DOM. Both objectOne and ObjectTwo exist as variables in memory within my service.