Angular-tree-component: Async Data not working

Created on 7 Oct 2017  路  2Comments  路  Source: CirclonGroup/angular-tree-component

Hi,

options = {
getChildren: (node:TreeNode) => {
return request('/api/children/' + node.id);
}
}

Am trying to get child nodes. in request('/api/children/' + node.id); calling rest services thats returning the child node. Because of asynchronous it's not working. how I can make it synchronous .I need child data needs to be loaded on demand.

Thanks

Most helpful comment

Hi Abhi,

Thanks so much .. it's working now.

really am struck with this issue.

Cheers
Chandu

All 2 comments

Hi @chandu58

You need to return Promise object for async data to make it work !

getChildren(node:TreeNode) {
    return new Promise((resolve, reject) => {
        this.yourService.getChildren(node.data).subscribe(data => {
          resolve(data );
        }, error => this.onLoadFailed(error));
    });
}

Assuming this.yourService.getChildren will be make actual call to your API (('/api/children/' + node.id))

Hope this will help.

Please share the output!

Cheers
Abhi

Hi Abhi,

Thanks so much .. it's working now.

really am struck with this issue.

Cheers
Chandu

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chpasha picture chpasha  路  5Comments

Shadowlauch picture Shadowlauch  路  5Comments

Gillardo picture Gillardo  路  5Comments

filipemansano picture filipemansano  路  5Comments

olastor picture olastor  路  5Comments