Skip to content

Commit 825e6fa

Browse files
committed
fix(cdk-experimental/scrolling): Fix ExpressionChangedAfterItWasCheckedError
This fixes an expressionchanged... error in the scrolling where template updates were not accompanied by a change notification (`markforCheck`/signal update, etc).
1 parent 82c4484 commit 825e6fa

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe('CdkVirtualScrollViewport', () => {
1717

1818
beforeEach(waitForAsync(() => {
1919
TestBed.configureTestingModule({
20-
providers: [provideCheckNoChangesConfig({exhaustive: false})],
2120
imports: [ScrollingModule, ExperimentalScrollingModule, AutoSizeVirtualScroll],
2221
});
2322
}));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
so that the scrollbar captures the size of the entire data set.
1111
-->
1212
<div class="cdk-virtual-scroll-spacer"
13-
[style.width]="_totalContentWidth" [style.height]="_totalContentHeight"></div>
13+
[style.width]="_totalContentWidth()" [style.height]="_totalContentHeight()"></div>

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
OnInit,
2424
Optional,
2525
Output,
26+
signal,
2627
ViewChild,
2728
ViewEncapsulation,
2829
} from '@angular/core';
@@ -137,10 +138,10 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
137138
private _totalContentSize = 0;
138139

139140
/** A string representing the `style.width` property value to be used for the spacer element. */
140-
_totalContentWidth = '';
141+
_totalContentWidth = signal('');
141142

142143
/** A string representing the `style.height` property value to be used for the spacer element. */
143-
_totalContentHeight = '';
144+
_totalContentHeight = signal('');
144145

145146
/**
146147
* The CSS transform applied to the rendered subset of items so that they appear within the bounds
@@ -533,9 +534,11 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
533534

534535
/** Calculates the `style.width` and `style.height` for the spacer element. */
535536
private _calculateSpacerSize() {
536-
this._totalContentHeight =
537-
this.orientation === 'horizontal' ? '' : `${this._totalContentSize}px`;
538-
this._totalContentWidth =
539-
this.orientation === 'horizontal' ? `${this._totalContentSize}px` : '';
537+
this._totalContentHeight.set(
538+
this.orientation === 'horizontal' ? '' : `${this._totalContentSize}px`,
539+
);
540+
this._totalContentWidth.set(
541+
this.orientation === 'horizontal' ? `${this._totalContentSize}px` : '',
542+
);
540543
}
541544
}

0 commit comments

Comments
 (0)