angular-tree-control icon indicating copy to clipboard operation
angular-tree-control copied to clipboard

Error when deleting a Node.

Open hummorsa opened this issue 9 years ago • 2 comments

Hi,

I am trying to delete a node by just doing a splice of a root node or a child node based on the parent node, like this:

if ($scope.obj.parentNode === null){ $scope.list.splice($scope.obj.index,1); }else{ // not a root node $scope.obj.parentNode.children.splice($scope.treeParameters.index,1); };

I store the $parent and $index in the 'obj' object on node selection.

every time I do either I get an error in this line b[$scope.options.nodeChildren] = []; in the following code, because b is NULL

function defaultEquality(a, b) { if (a === undefined || b === undefined) return false; a = shallowCopy(a); a[$scope.options.nodeChildren] = []; b = shallowCopy(b); b[$scope.options.nodeChildren] = []; return angular.equals(a, b); }

and the error say:

TypeError: Cannot set property 'children' of null at Object.defaultEquality as equality

Any suggestion ? thanks in advance.

hummorsa avatar Mar 04 '16 20:03 hummorsa

this is solved,

the error was happening because I was setting to null the property "selected-node" and it looks the selected-node don't get clear if you delete it from the array. I am missing the correct way to clear the selected-node ?

hummorsa avatar Mar 04 '16 21:03 hummorsa

I think we have the same issue(#194), because like you I set the selected-node to null. Your solution is the only one if they don't change their defaultEquality function. But I thought they would do the necessary to correct it and accept null as undefined.

Ajrarn avatar Mar 04 '16 22:03 Ajrarn