CirclonGroup / angular-tree-component

A simple yet powerful tree component for Angular (>=2)
https://angular2-tree.readme.io/docs
MIT License
1.1k stars 492 forks source link

getFirstRoot not work in async/await #895

Open YongChingShieh opened 3 years ago

YongChingShieh commented 3 years ago

getFirstRoot not work in async/await

my code:

async ngOnInit(): Promise<void> { await this.initTree(); } async initTree(): Promise<void> { const obj = await this.http.post("api/Dictionary/GetDicInfoTree").toPromise(); this.nodes = generateTree(JSON.parse(obj.Extension)); let firstroot = this.tree.treeModel.getFirstRoot(); console.log(firstroot); console.log(this.tree.treeModel); console.log(this.nodes); };

this.tree.treeModel.getFirstRoot() is null but this.nodes is not null

QQ截图20210219150028

tobiasengelhardt commented 3 years ago

Hi @yongqingxie, what version of the tree are you using? We did a fix for this yesterday. It's in version 11.0.3. Version 11.0.0 - 11.0.2 have wrong getFirstRoot calls. Can you try the new version and let me know?

YongChingShieh commented 3 years ago

Hi @yongqingxie, what version of the tree are you using? We did a fix for this yesterday. It's in version 11.0.3. Version 11.0.0 - 11.0.2 have wrong getFirstRoot calls. Can you try the new version and let me know? this my version info "@angular/core": "~11.1.0", "@angular/cli": "~11.1.1", "@angular/compiler-cli": "~11.1.0", "@angular/language-service": "~11.1.0", "@circlon/angular-tree-component": "^11.0.3", if i use async/await
getFirstRoot is null getNodeById and getNodeByPath is undefined

tobiasengelhardt commented 3 years ago

We had a bit of trouble removing lodash so I thought it might be related. But it's not. I can reproduce this as well. Will take a look into it and keep you updated.