79690232

Date: 2025-07-04 13:12:54
Score: 0.5
Natty:
Report link

I was able to get the desired output by replacing
this.dataSource.data.slice();
with
JSON.parse(JSON.stringify(this.dataSource.data));,
which performs a deep copy.
I also changed the HTML from:

<div role="group">
  <ng-container matTreeNodeOutlet></ng-container>
</div>

to:

<div role="group" *ngIf="treeControl.isExpanded(node)">
  <ng-container matTreeNodeOutlet></ng-container>
</div>

to conditionally render the child nodes only when the current node is expanded.
If the problem still isn't solved, you can check this StackOverflow link for help:

How to update nested mat-tree dynamically

Reasons:
  • Blacklisted phrase (1): StackOverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Navid Abedini