Skip to content

Commit 265fb13

Browse files
committed
fix(cdk/scrolling): avoid injector errors
Fixes some "Injector is already destroyed" errors.
1 parent 996d44d commit 265fb13

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
ElementRef,
1818
inject,
1919
Inject,
20-
Injector,
2120
Input,
2221
OnDestroy,
2322
OnInit,
@@ -178,8 +177,6 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
178177
/** Subscription to changes in the viewport size. */
179178
private _viewportChanges = Subscription.EMPTY;
180179

181-
private _injector = inject(Injector);
182-
183180
private _isDestroyed = false;
184181

185182
constructor(...args: unknown[]);
@@ -243,6 +240,9 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
243240
}
244241

245242
override ngOnDestroy() {
243+
this._isDestroyed = true;
244+
this._isChangeDetectionPending = false;
245+
this._runAfterChangeDetection = [];
246246
this.detach();
247247
this._scrollStrategy.detach();
248248

@@ -251,8 +251,6 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
251251
this._detachedSubject.complete();
252252
this._viewportChanges.unsubscribe();
253253

254-
this._isDestroyed = true;
255-
256254
super.ngOnDestroy();
257255
}
258256

@@ -526,7 +524,7 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
526524
fn();
527525
}
528526
},
529-
{injector: this._injector},
527+
{manualCleanup: true},
530528
);
531529
});
532530
}

0 commit comments

Comments
 (0)