当用户滚动到列表的末尾时,需要调用API,以使用Angular CDK虚拟滚动加载下一批数据
我正在使用以下逻辑来确定用户是否在列表的末尾。但是,在以下情况下,end === total
多次触发多个API调用。实际末端和总数应仅在用户处于列表末尾时仅一次。有人可以指出为什么这种奇怪的行为吗? scrollChange是在html (scrolledindexchange)中触发
scrollChange(e: any) {
const end = this.viewport.getRenderedRange().end;
const total = this.viewport.getDataLength();
if (end === total) {
console.log('end reached');
// Call my API to update my list
}
的
I am using below logic to determine if User is at the end of the List. However in the Below case end === total
multiple times which is triggering multiple API calls. In actual end and total should be equal only once when the user is at the end of the List. Can any one point out why such strange behaviour? ScrollChange is triggered in HTML (scrolledIndexChange)="scrollChange($event)"
scrollChange(e: any) {
const end = this.viewport.getRenderedRange().end;
const total = this.viewport.getDataLength();
if (end === total) {
console.log('end reached');
// Call my API to update my list
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论