angular-tree-component icon indicating copy to clipboard operation
angular-tree-component copied to clipboard

Changing the reference to nodes will report "ERROR TypeError: Cannot read property 'data' of null"

Open Hongyu-Zhuo opened this issue 4 years ago • 5 comments

Minimal reproduction of the bug/regression with instructions:

https://stackblitz.com/edit/angular-tree-component-demo?file=src%2Fapp%2Fapp.component.html

Click the "update tree nodes" button will see the error, But the tree nodes are updated success.

Expected behavior:

No Error report.

Versions of Angular Tree Component, Angular, Node, affected browser(s) and operating system(s):

@circlon/angular-tree-component   ^10.0.0

@angular-devkit/architect          0.1100.2
@angular-devkit/build-angular      0.1100.2
@angular-devkit/core               11.0.2
@angular-devkit/schematics         11.0.2
@angular/cdk                       11.0.1
@angular/flex-layout               10.0.0-beta.32
@angular/material                  11.0.1
@angular/material-moment-adapter   11.0.1
@schematics/angular                11.0.2
@schematics/update                 0.1100.2
ng-packagr                         11.0.3
rxjs                               6.5.5
typescript                         4.0.5

system:

MacOS v10.14.6

Other information:

The error threw in node.isRoot method;

I would be willing to submit a PR to fix this issue

I'm not sure. [ ] Yes (Assistance will be provided if you need help to submit a pull request) [ ] No

Hongyu-Zhuo avatar Dec 18 '20 08:12 Hongyu-Zhuo

The error is reported in:

// projects/angular-tree-component/src/lib/models/tree-node.model.ts 70:45
get isRoot(): boolean { return this.parent.data.virtual; }

Modify to:

get isRoot(): boolean { return this.parent?.data.virtual; }

Hongyu-Zhuo avatar Dec 22 '20 06:12 Hongyu-Zhuo

Still not sure that it's OK, but instead of node.IsRoot you can write node.parent == null || node.parent.data.virtual Here is my workaround: <div *ngIf="(node.parent == null || node.parent.data.virtual)" class="inline p-w-xxs">...</div>

eviltube avatar Jun 07 '21 11:06 eviltube

The error is reported in:

// projects/angular-tree-component/src/lib/models/tree-node.model.ts 70:45
get isRoot(): boolean { return this.parent.data.virtual; }

Modify to:

get isRoot(): boolean { return this.parent?.data.virtual; }

This is required since node.setActiveAndVisible() method internally calls node.isRoot which gives error.

sanket-thotange avatar Feb 02 '22 10:02 sanket-thotange

Facing same issue.. Any fix or workaround to this?

AkshayNaik033 avatar Mar 11 '22 09:03 AkshayNaik033

One thing can be done is to call node = this.tree.treeModel.getNodeById(node.id) and then go on with your operations

iamsank8 avatar Mar 11 '22 09:03 iamsank8