2
votes

I'm using the Angular Material Tree in my project. Is it possible to have the tree opened by default.

I'm using the last example via Tree with partially loaded data: https://stackblitz.com/angular/pyyaxgjpqnn?file=app%2Ftree-loadmore-example.ts

Thanks for your help.

I tried this solution but I have this error : ERROR Error: "ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'aria-expanded: false'. Current value: 'aria-expanded: true'."


    ngAfterViewInit() {
      this.treeControl.expandAll();
    }

1
does expandAll working? - Chellappan வ
no is not working - Paul Chris

1 Answers

2
votes

for whatever reason the nestedTreeControl.dataNodes does not get updated properly. update it with the same data you used for the nestedDataSource and it should work.

 this.store.select(r => entity).subscribe(r => {
        this.nestedDataSource.data = [new Entity(JSON.parse(JSON.stringify(r)))];
        this.nestedTreeControl.dataNodes = this.nestedDataSource.data;
        this.nestedTreeControl.expandAll();
      })