TLDR: have a list of items that need to be in a virtual scroll. It works fine, but only takes up ~30% of the space available until the screen size is changed. (make the dev tools larger).
On initial page load:

After resizing the page:

Here is a stripped back version of the template:
<cdk-virtual-scroll-viewport class="Viewport" itemSize="50">
<div *cdkVirtualFor="let item of threadsDetails$ | async" class="Item">
{{ item.thread.id }}
</div>
</cdk-virtual-scroll-viewport>
scss:
.Viewport {
height: 100%;
}
.Item {
border-bottom: solid 1px black;
height: 50px;
}
After looking into the Angular chrome tools, it seems that the ngDoCheck is triggered on page resize.
Things i have tried to solve this:
markForCheckcdk-virtual-scroll-viewport. (this works, but i still get the initial 30% then after re initing the full height is taken).Any ideas?
Have fixed this. Needed to call checkViewportSize() on CdkVirtualScrollViewport.
@ViewChild(CdkVirtualScrollViewport, { static: false })
private cdkVirtualScrollViewport: CdkVirtualScrollViewport;
this.threadDetailsSubscription = this.threadsDetails$
.pipe(
distinctUntilChanged(),
)
.subscribe(() =>
this.cdkVirtualScrollViewport?.checkViewportSize(),
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With