angular - 如何检测用户已到达虚拟滚动角度 7 中的列表末尾?
问题描述
我从 25 个批次的 rest api 获取数据。我正在使用虚拟滚动来显示数据。现在当这 25 个项目滚动时,我需要查询接下来的 25 个项目。如何检测用户何时到达列表末尾? ?
解决方案
Get reference of Virtual Scroll using the @ViewChild
@ViewChild(CdkVirtualScrollViewport)
viewport: CdkVirtualScrollViewport;
To check scroll reach to end using below code.
const end = this.viewport.getRenderedRange().end;
and using following condition you can determine the reached at end to load next items
const total = this.viewport.getDataLength();
if (end === total) {
//Load next items
}
Here is example infinite-virtual-scroll-angular
推荐阅读
- laravel - select2 远程搜索在liverwire 中不起作用
- angular - 页面刷新时延迟canActivate调用以等待数据加载
- jquery-select2 - Laravel-livewire 多选2
- mysql - 如何托管两个具有不同 mysql 版本的“phpmyadmin”?
- python - postgres使用python批量删除查询
- javascript - 为什么 JavaScript 和 HTML 不允许我使用“clear”这个词作为函数的名称?
- c++ - C++ 交换指针 - 不能通过明确定义类型来重现自动类型
- r - 重新排列使用 ggsurv 绘制 Kaplan Meier 曲线的图例顺序
- webpack - 无法构建 Next.js 应用程序并将其部署到 vercel:ModuleNotFoundError:找不到模块:错误:空依赖项(无请求)
- swift - 表格视图的自定义 headerView