valor-software / ng2-tree

Angular tree component

Home Page:http://valor-software.com/ng2-tree/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reconstruct tree and access controller in same method (controller is null)

NewteqDeveloper opened this issue · comments

We are having a problem with the getControllerByNodeId method on the treeComponent if we have recreated a tree dynamically and then want to access the controller to expand the nodes.

Basically, we do the following in a method

// create resultTree as TreeModel
this.tree = resultTree
const controller = this.treeComponent.getControllerByNodeId(lastNodeId)
controller.expandToParent()

The problem that we have is that the controller is null.

My guess is that it's because the treeComponent has not yet been updated with the new tree data when the call to the treeComponent happens.

I would like to know (because I can't seem to find it on the documentation) if there is a "callback" method that can be used for when the tree is updated in the treeComponent. I believe that this would cause the call to the getControllerByNodeId method to have the correct data

I'm not sure how to apply the label - Help Wanted

I actually tried the following:

// create resultTree as TreeModel
this.tree = resultTree
setTimeout(() => {
        const controller = this.treeComponent.getControllerByNodeId(lastNodeNumber);
        controller.expandToParent()
      }, 5000);

But the controller is still null. Any ideas?

I'm having the same problem, is there a solution to this?

I haven't found a solution to this yet. I think that some changes are required from the library

@nfourie-work-profile @MickGyver

add keepNodesInDOM : true to settings.

I will give this a try and revert back if there is still a problem

I'm having the same problem. Did you find a solution?

  handleExpandedEvent(event: NodeExpandedEvent) {
    const node = event.node;
    const controller = this.component.getControllerByNodeId(node.id);
    this.log.debug("node.id=",node.id, "; controller is null:", controller===null);
    this.dept.fetchSubordinatesOf(<number>node.id).subscribe(depts => {
      this.log.debug("controller is null:", controller===null);
    });
  }

Unfortunately I have not yet been able to test the suggested approach in our current project. Once I get to test the suggested approach, I will revert back.