1

When I filter the array we have less data we are not getting the vertical scroll. So *cdkVirtualFor not re-rendering the UI. It works when we have more data.

If I use *ngFor always it works.

Using *ngFor is the better choice for my case or still we can use *cdkVirtualFor and make some changes to fix this?

or is this related to height of the cdk-virtual-scroll-viewport?

Gnik
  • 7,120
  • 20
  • 79
  • 129

1 Answers1

0

in FixedSizeVirtualScrollStrategy which is the default, there is a method named onDataLengthChanged. it is only called when the reference of the passed items is changed. so to see the effect you should replace the whole array of items. in other word you should see your array as an immutable array. for example if i have an array of 100 items and run the below code on it the virtual scroll would not update itself, because the array reference didn't change.

    let i = 90;
    while (i > 0) {
      i--;
      this.items.pop();
    }

but if I replace the array reference with a code like below. it will understand it. and update itself

this.items = this.items.splice(0, 10);
Stef
  • 203
  • 2
  • 9