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?
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();
}