angular-tree-control
angular-tree-control copied to clipboard
Error when deleting a Node.
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.
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 ?
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.