Angular material tree expand a particular node

androidGenX picture androidGenX · Apr 9, 2019 · Viewed 10.6k times · Source

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.

Answer

bugs picture bugs · Apr 9, 2019

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