Angular virtual scroll: append new items when reaching the end of scroll

后端 未结 2 1473
南笙
南笙 2021-02-19 05:52

I would like to use virtual scroll on my Angular application. The items in my list are the result of a remote paged search. I would like to load more results (call the next page

2条回答
  •  悲&欢浪女
    2021-02-19 06:31

    The easiest way to solve this is with the scrolledIndexChange.

    
    

    $event is the first index of rendered elements at the moment. Therefore, you can call the next page when the index of the first item is near the end of the items in the list

    Remember that the items have a fixed height (itemSize) so it is easy to identify the amount of elements that are rendered at a time.

    e.g.

      nextBatch(index) {
        if (index + $itemsRenderAtTheMoment === this.items.length - 1) {
          this.page ++;
          this.loadMore();
        }
      }
    

提交回复
热议问题