Skip to content

Commit 1d6b39b

Browse files
committed
refactor(cdk/scrolling): refactors CdkVirtualScrollViewport destroyed flag
Refactors the viewport destruction logic to use the `DestroyRef` service, removing the need for a custom `_isDestroyed` flag.
1 parent eb6ace5 commit 1d6b39b

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/cdk/scrolling/virtual-scroll-viewport.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
179179

180180
private _injector = inject(Injector);
181181

182-
private _isDestroyed = false;
182+
private _destroyRef = inject(DestroyRef);
183183

184184
constructor(...args: unknown[]);
185185

@@ -211,7 +211,7 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
211211
// effect that runs before change detection of any application views (since we're depending on markForCheck marking parents dirty)
212212
{injector: inject(ApplicationRef).injector},
213213
);
214-
inject(DestroyRef).onDestroy(() => void ref.destroy());
214+
this._destroyRef.onDestroy(() => void ref.destroy());
215215
}
216216

217217
override ngOnInit() {
@@ -262,8 +262,6 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
262262
this._detachedSubject.complete();
263263
this._viewportChanges.unsubscribe();
264264

265-
this._isDestroyed = true;
266-
267265
super.ngOnDestroy();
268266
}
269267

@@ -512,7 +510,7 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
512510

513511
/** Run change detection. */
514512
private _doChangeDetection() {
515-
if (this._isDestroyed) {
513+
if (this._destroyRef.destroyed) {
516514
return;
517515
}
518516

0 commit comments

Comments
 (0)