I neeed to replace some data on the tree, then run treemodel.update() and after that select a node. Tree is already rendered at that time. This is my code:
@ViewChild('resulttree') resulttree: ElementRef;
updateResulttree(id: number) {
for (let node of this.resultNodes) {
node.children[0].children = node.children[0].children.filter(childnode => childnode.selected);
node.children[1].children = node.children[1].children.filter(childnode => childnode.selected);
}
this.resulttree.treeModel.update();
setTimeout(() => {
const someNode = this.resulttree.treeModel.getNodeBy(node => node.data.tree_node_id === id);
someNode.setActiveAndVisible();
}, 100);
}
This workarond with setTimeout works, but it's not good. If the update() Method takes more than 100ms, "someNode" will be undefined.
Any ideas how to make it better?
Angular 10, AngularTreeCompoment 10.0.2 https://angular2-tree.readme.io/docs/getting-started