Skip to content

Commit a4ec21a

Browse files
authored
fix(module:graph): remove NgZone dependency (#8460)
This commit eliminates the `NgZone` dependency from the graph edge component. Since zone.js is becoming optional, `onStable` won't emit any value when `provideZonelessChangeDetection` is used in the application config. Instead, we now use the alternative approach provided by `afterNextRender`. Most of the code that was using `onStable` should be replaced with `afterNextRender`.
1 parent 3bd6d48 commit a4ec21a

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

components/graph/graph-edge.component.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import {
99
ChangeDetectorRef,
1010
Component,
1111
ElementRef,
12+
Injector,
1213
Input,
13-
NgZone,
1414
OnChanges,
1515
OnInit,
1616
SimpleChanges,
17-
TemplateRef
17+
TemplateRef,
18+
afterNextRender,
19+
inject
1820
} from '@angular/core';
19-
import { take } from 'rxjs/operators';
2021

2122
import { curveBasis, curveLinear, line } from 'd3-shape';
2223

@@ -61,9 +62,10 @@ export class NzGraphEdgeComponent implements OnInit, OnChanges {
6162
.y(d => d.y)
6263
.curve(curveLinear);
6364

65+
private injector = inject(Injector);
66+
6467
constructor(
6568
private elementRef: ElementRef<SVGGElement>,
66-
private ngZone: NgZone,
6769
private cdr: ChangeDetectorRef
6870
) {
6971
this.el = this.elementRef.nativeElement;
@@ -75,17 +77,22 @@ export class NzGraphEdgeComponent implements OnInit, OnChanges {
7577

7678
ngOnChanges(changes: SimpleChanges): void {
7779
const { edge, customTemplate, edgeType } = changes;
80+
7881
if (edge) {
79-
this.ngZone.onStable.pipe(take(1)).subscribe(() => {
80-
// Update path element if customTemplate set
81-
if (customTemplate) {
82-
this.initElementStyle();
83-
}
82+
afterNextRender(
83+
() => {
84+
// Update path element if customTemplate set
85+
if (customTemplate) {
86+
this.initElementStyle();
87+
}
8488

85-
this.setLine();
86-
this.cdr.markForCheck();
87-
});
89+
this.setLine();
90+
this.cdr.markForCheck();
91+
},
92+
{ injector: this.injector }
93+
);
8894
}
95+
8996
if (edgeType) {
9097
const type = this.edgeType === NzGraphEdgeType.LINE ? curveLinear : curveBasis;
9198
this.line = line<{ x: number; y: number }>()

0 commit comments

Comments
 (0)