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?

1 Answer 1

1

I was not publishing after updating the treeData.

this.dataService.getFolders().subscribe(data => {
      this.treeData.push(data);
      this.dataChange.next(this.treeData);
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.