Skip to content

Commit 0829098

Browse files
committed
fix(cdk/scrolling): Move setting transform outside afterNextRender
1 parent f8c0b8d commit 0829098

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,20 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
511511
}
512512

513513
this.ngZone.run(() => {
514+
// Apply changes to Angular bindings. Note: We must call `markForCheck` to run change detection
515+
// from the root, since the repeated items are content projected in. Calling `detectChanges`
516+
// instead does not properly check the projected content.
514517
this._changeDetectorRef.markForCheck();
518+
519+
// Apply the content transform. The transform can't be set via an Angular binding because
520+
// bypassSecurityTrustStyle is banned in Google. However the value is safe, it's composed of
521+
// string literals, a variable that can only be 'X' or 'Y', and user input that is run through
522+
// the `Number` function first to coerce it to a numeric value.
523+
this._contentWrapper.nativeElement.style.transform = this._renderedContentTransform;
524+
515525
afterNextRender(
516526
() => {
517527
this._isChangeDetectionPending = false;
518-
// Apply the content transform. The transform can't be set via an Angular binding because
519-
// bypassSecurityTrustStyle is banned in Google. However the value is safe, it's composed of
520-
// string literals, a variable that can only be 'X' or 'Y', and user input that is run through
521-
// the `Number` function first to coerce it to a numeric value.
522-
this._contentWrapper.nativeElement.style.transform = this._renderedContentTransform;
523528
const runAfterChangeDetection = this._runAfterChangeDetection;
524529
this._runAfterChangeDetection = [];
525530
for (const fn of runAfterChangeDetection) {

0 commit comments

Comments
 (0)