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

Checking node with not-yet-loaded children causes an exception

Open m-bobrowicz opened this issue 8 years ago • 6 comments

Hi there,

I'm having some issues combining lazy loading with checkboxes. Checking a node with hasChildren: true when the children are not loaded yet causes an exception. See plunkr: https://plnkr.co/edit/wigPSzzk3R0XM9RE173D?p=preview

Steps to reproduce:

  1. Check Root2

SecondChild has one async loaded child and is not checked after expanding. After all the async children are loaded the issue disappears.

Is there a way to work around this or is this a bug?

Stack trace from plunkr:

ERROR TypeError: Cannot read property 'forEach' of undefined
    at e.setIsSelected (VM630 [email protected]:1)
    at eval (VM630 [email protected]:1)
    at Array.forEach (<anonymous>)
    at ObservableArray.eval (VM672 mobx@^3:697)
    at e.setIsSelected (VM630 [email protected]:1)
    at e.toggleSelected (VM630 [email protected]:1)
    at TOGGLE_SELECTED (VM630 [email protected]:1)
    at e.mouseAction (VM630 [email protected]:1)
    at Object.eval [as handleEvent] (VM674 e.ngfactory.js:13)
    at handleEvent (VM627 core.umd.js:13620)

Thanks for the work on the tree component and looking forward to hearing from you.

m-bobrowicz avatar Dec 20 '17 16:12 m-bobrowicz

+1

ghost avatar Jan 08 '18 13:01 ghost

+1. Has there been any updates on this issue?

barry-ryan avatar Jan 08 '18 13:01 barry-ryan

Here is a fix that I have issued in a local branch. I attempted to push this up to the repo in a new branch but access was denied

In tree-node.model.ts / setIsSelected

  setIsSelected(value) {
    if (this.isLeaf || !this.children) {
      this.treeModel.setSelectedNode(this, value);
    } else {
      this.children.forEach((child) => child.setIsSelected(value));
    }

    return this;
  }

ghost avatar Jan 09 '18 10:01 ghost

+1

wendelstam avatar Jan 11 '18 10:01 wendelstam

@jlewisitv Could you success to commit it? @ilyagelman could you please consider it?

I have faced to it too. I don't know there is other solutions or not! but I think that it should be right.

omid-nazifi avatar Feb 01 '18 10:02 omid-nazifi

I could not create a new branch and push I was unauthorised and therefor could not create a pull request

ghost avatar Feb 01 '18 10:02 ghost