2

I am facing an issue with material tree control on Angular 6. When I use static data and return it as an observable using RxJS 'from' operator, it works fine. However, I have a web API returning similar model data which I am calling using http client get and returns a JSON. It is however not rendering the tree control in that case. Possibly, since earlier I used static data it returned quickly and with async data the UI is binding before data is actually being returned.

ngOnInit:void{
 this.nestedTreeControl = new NestedTreeControl<any>(this._getChildren);
    this.nestedDataSource = new MatTreeNestedDataSource();
    this.dataChange.subscribe(data => this.nestedDataSource.data = data);
    this.dataChange.next(this.treeData);
    this.dataService.getFolders().subscribe(data => {
      this.treeData.push(data);
    })
}

Where am I going wrong, Can anyone please pinpoint the problem?

Tauseef Malik
  • 128
  • 1
  • 7

1 Answers1

1

I was not publishing after updating the treeData.

this.dataService.getFolders().subscribe(data => {
      this.treeData.push(data);
      this.dataChange.next(this.treeData);
})
Tauseef Malik
  • 128
  • 1
  • 7