Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular material tree expand a particular node

I have seen various examples to expand all nodes in mat-tree using

expandAll()

Is there any mechanism to expand a particular node if we click on it. Something like

node.expand()

I had referred angular material documentation but not got any answer. Please guide if anyone gone through it.

like image 677
androidGenX Avatar asked Apr 09 '19 10:04

androidGenX


1 Answers

What you are looking for is the expand method on treeControl, which operates on the treeControl.dataNodes array.

Something like

this.treeControl.expand(this.treeControl.dataNodes[/** node you want to expand **/]);

Just keep in mind that if you want to expand a particular node, all its ancestors up to the root need to be expanded as well.


Demo

like image 192
bugs Avatar answered Oct 20 '22 11:10

bugs