Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update nested mat-tree dynamically

I have an Angular material component that I am trying to update dynamically with new data.

@ViewChild('tree') tree: MatTree<any>;
...
treeControl: NestedTreeControl<any>;
dataSource: MatTreeNestedDataSource<any>;
...
// This does not work
this.tree.renderNodeChanges(newData);

I can change the data source data just fine and it is reflected in the logs, but the tree is never re-rendered this.dataSource.data = newData;

This data is retrieved from an observable and I pass it in every time there is a change.

<mat-tree [dataSource]="dataSource"
  [treeControl]="treeControl"
  #tree
  class="release-notes-tree">
  ...
</mat-tree>

What is the easiest way to just pass in brand new data and update the tree?

like image 549
theblindprophet Avatar asked Jun 21 '18 20:06

theblindprophet


1 Answers

Can't you just make the dataSource a Subject then when you want to change it call dataSource.next() ?

like image 85
wz2b Avatar answered Sep 29 '22 21:09

wz2b