10

Trying to get cdk-virtual-scroll-viewport height to be equal to page height.

<div class="plServiceItemsList-list">
    <cdk-virtual-scroll-viewport class="plServiceItemsList-listViewPort" itemSize="20">

When trying to use height 100%, I see no list

.plServiceItemsList-listViewPort {
  height: 100%;
  min-height: 100%;
}

The only way it will be displayed is specifying a height:

.plServiceItemsList-listViewPort {
  height: 100px;
}

But this is not dynamic.

2
  • 3
    Did you tired 100vh? Commented Feb 26, 2019 at 15:31
  • @Chellappan thanks! Works
    – MCMatan
    Commented Feb 26, 2019 at 15:48

1 Answer 1

14

After @Chellappan suggested using vh, I thought my issue was solved, but actually, when the page size what bigger than the screen, it failed.

This is what I used:

.plServiceItemsList-listContainer {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.plServiceItemsList-listViewPort {
  flex-grow: 1;
}
3
  • 1
    Thank you @MCMatan for sharing. I've been working to fill vertical space in a view between fixed header and footer using @angular/flex-layout, so I just used fxFlex="grow" on the scroller inside a flex container, just as you point out!
    – Larry King
    Commented Jul 29, 2019 at 20:23
  • 2
    @MCMatan this solution doesn't do the trick for me, the listcontainer class is that just a div wrapped around the <cdk-virtual-scroll-viewport>?
    – r0699049
    Commented Oct 23, 2020 at 13:02
  • 3
    not work for me. not change the height as expected Commented Mar 22, 2021 at 12:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.