0

I want to expand the first node on startup. I saw here the way to go. The difference is that I don't have the nodes in my code but get it from my databse. This is my Code:

this.appService.getTreeStructure().then((treeNodes) => {
      this.nodes = treeNodes;
      const treeModel: TreeModel = this.treeComponent.treeModel;
      console.log(treeModel);
      const firstNode: TreeNode = treeModel.getFirstRoot();
      console.log(firstNode);
      firstNode.expand();
    });

That doesnt work. the first console log shows that treeModel is an object but the second one is undefined. I can the a nodes property in treeModel that has allready all the nodes in it from the first output but I cant get access to them.

How can I expande the first node on startup?

3
  • Can you recreate this in a stackblitz? There's not enough information to go on here. Commented Feb 11, 2020 at 8:02
  • I dont know About stackblitz. But I just make a normal tree with angular tree component with node binding to nodes. The Code in my question is located in the 'ngOnInit' function. Commented Feb 11, 2020 at 8:44
  • Google is your friend: stackblitz.com. It's a way for you to create a live example of your problem so that people who want to help you can easily see what's going on without guessing at what might be wrong with code that isn't given in the question. Commented Feb 11, 2020 at 9:11

1 Answer 1

2

When you update your nodes you need to listen to the updateData Event.

<tree-root [nodes]="nodes" (updateData)="onUpdateData()"></tree-root>

onUpdateData() {
      const treeModel: TreeModel = this.treeComponent.treeModel;
      const firstNode: TreeNode = treeModel.getFirstRoot();
      firstNode.expand();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.