Skip to content

Commit

Permalink
fix(cdk/scrolling): avoid injector errors
Browse files Browse the repository at this point in the history
Fixes some "Injector is already destroyed" errors.
  • Loading branch information
crisbeto committed Dec 9, 2024
1 parent 996d44d commit 265fb13
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/cdk/scrolling/virtual-scroll-viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
ElementRef,
inject,
Inject,
Injector,
Input,
OnDestroy,
OnInit,
Expand Down Expand Up @@ -178,8 +177,6 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
/** Subscription to changes in the viewport size. */
private _viewportChanges = Subscription.EMPTY;

private _injector = inject(Injector);

private _isDestroyed = false;

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

override ngOnDestroy() {
this._isDestroyed = true;
this._isChangeDetectionPending = false;
this._runAfterChangeDetection = [];
this.detach();
this._scrollStrategy.detach();

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

this._isDestroyed = true;

super.ngOnDestroy();
}

Expand Down Expand Up @@ -526,7 +524,7 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
fn();
}
},
{injector: this._injector},
{manualCleanup: true},
);
});
}
Expand Down

0 comments on commit 265fb13

Please sign in to comment.