I have recursive tree component and I would like to expand all nodes on click from parent component, how can I do this? More details in plunker.
I talking about this method:
expandAll(){
console.log("expanded all");
}
I have recursive tree component and I would like to expand all nodes on click from parent component, how can I do this? More details in plunker.
I talking about this method:
expandAll(){
console.log("expanded all");
}
Just add an expandAll() method to the TreeComponent that expands all nodes and calls expandAll() on all nested TreeComponent components.
You can get all nested TreeComponent components by adding
@ViewChildren(TreeComponent) subTrees:QueryList<TreeComponent>;
and call the method on the childs like
expandAll() {
for(var subTree of this.subTrees.toArray()) {
subTree.expandAll();
}
}
@ViewChild())After a while I guess I figure it out. I just added one more @Input() in TreeComponent:
@Input() expandAll: boolean;
and replaced *ngIf recursive condition to:
[hidden]="(!expanded[i] && !expandAll) || (expanded[i] && expandedAll)"
Its need a bit more work (collapsing all doesnt work that how it should), but it works that how I wanted.