angular mat-tree collapse automatically on datasource update?

Viewed 34

angular mat-tree collapse automatically when datasource is updated. I have tried with custom expanded but it is not working. by default expanded value is false.

toggleNode(node:ZipFilesFlatNode){
    node.isLoading=true;
    node.expanded=!node.expanded;
    this.api.getRunFile(url).subscribe((res)=>{
      node.isLoading=false;
      this.dataSource.data=res.data;
      console.log(this.dataSource.data)
    },err=>{
      node.isLoading=false;
    })
  }
<mat-tree [dataSource]="dataSource" [treeControl]="treeControl">
          <mat-tree-node *matTreeNodeDef="let node" matTreeNodePadding>
            <button mat-icon-button disabled></button>
            {{node.name}}c
          </mat-tree-node>
          <mat-tree-node *matTreeNodeDef="let node; when: hasChild" matTreeNodePadding>
            <button mat-icon-button
                    [attr.aria-label]="'Toggle ' + node.name"  (click)="toggleNode(node)">
              <mat-icon class="mat-icon-rtl-mirror">
                {{node.expanded ? 'expand_more' : 'chevron_right'}}
              </mat-icon>
            </button>
            {{node.name}}p
            <mat-progress-bar *ngIf="node.isLoading"
                              mode="indeterminate"
                              class="example-tree-progress-bar"></mat-progress-bar>
          </mat-tree-node>
 </mat-tree>
        
0 Answers
Related