Came across a similar problem at work late on Friday, wasn't happy with the result so mocked up a stackblitz that might meet your needs.
@Jaikumar's link was helpful - https://material.angular.io/cdk/tree/api#NestedTreeControl.
See this modified stackblitz - https://stackblitz.com/angular/lneeokqoxvm based on the matTree example for a working example.
The key, apart from modifying the interface to fit a loose datastructure was in the NestTreeControl the function at the end appears to be the property/function getChildren.
interface FoodNode {
name: string;
children?: FoodNode[];
}
...
new NestedTreeControl<FoodNode>(node => node.children)
modified to:
interface FoodNode {
name: string;
children?: FoodNode[];
subChildren?: FoodNode[];
}
...
new NestedTreeControl<FoodNode>(node => {
return (node.children) ? node.children : node.subChildren;
});
The hasChild function at the end of the class has to allow for the added complexity as well:
hasChild (_: number, node: FoodNode): boolean {
return (node.subChildren) ?
!!node.subChildren && node.subChildren.length > 0 :
!!node.children && node.children.length > 0;
}
The double bang !! made me find this reference - https://medium.com/better-programming/javascript-bang-bang-i-shot-you-down-use-of-double-bangs-in-javascript-7c9d94446054
Hope you find this helpful even though you asked the question months ago.