Bug
Collapse All/Expand All on Nested Tree Control
The expandAll() in nested-tree-control.ts function doesn't work. this.dataNodes is undefined
https://angular-7dvgw3.stackblitz.io
@angular/material 6.3.3
I have the same problem. I simply added a call to expandAll() to the example from the doc: https://ynxoygyknxk.angular.stackblitz.io/
See the console for the error.
I checked the source code and judging from the test file you have to set the dataNodes value yourself.
Notice the treeControl.dataNodes = nodes; before calling expandAll()
https://github.com/angular/material2/blob/adda21f5c2d47ce12620567cda9494e68d092339/src/cdk/tree/control/nested-tree-control.spec.ts#L74-L93
Ran into the same issue. From testing it does appear there is a dependency on expandAll /collapseAll /expand etc. relying treeControl.dataNodes field. When I look at the examples here: [https://material.angular.io/components/tree/examples] I notice that the first example populates dataNodes but the others don't.
That said, this case can probably be closed as a duplicate of the issue noted here : https://github.com/angular/material2/issues/12469. Not sure if ultimately the problem is just documentation OR if there is a "bug".
Most helpful comment
I checked the source code and judging from the test file you have to set the dataNodes value yourself.
Notice the
treeControl.dataNodes = nodes;before callingexpandAll()https://github.com/angular/material2/blob/adda21f5c2d47ce12620567cda9494e68d092339/src/cdk/tree/control/nested-tree-control.spec.ts#L74-L93