[英]How to track the scroll event of individual cdk-virtual-scroll-viewport
I am using cdk-virtual-scroll-viewport
to build pagination scroll in my app.我正在使用
cdk-virtual-scroll-viewport
在我的应用程序中构建分页滚动。 I have two instances of cdk-virtual-scroll-viewport
, Want to track individual scroll events and make API call for the individual scrolls.我有两个
cdk-virtual-scroll-viewport
实例,想要跟踪单个滚动事件并为单个滚动进行 API 调用。 How to achieve that?如何做到这一点?
Stackblitz URL https://stackblitz.com/edit/angular-cdk-programatically-scroll-uqgvpu?file=app%2Fcdk-virtual-scroll-fixed-buffer-example.html
Stackblitz URL https://stackblitz.com/edit/angular-cdk-programatically-scroll-uqgvpu?file=app%2Fcdk-virtual-scroll-fixed-buffer-example.html
Just use @ViewChild
with each component selector.只需将
@ViewChild
与每个组件选择器一起使用。
First in HTML template, declare a template variable for each component, by using hash symbol and name on component tag :首先在 HTML 模板中,通过在组件标签上使用井号和名称为每个组件声明一个模板变量:
<cdk-virtual-scroll-viewport #cmp1 itemSize="50".../>
Then use @ViewChild decorator in order to query component, and be able to reference it inside code :然后使用@ViewChild装饰器来查询组件,并能够在代码中引用它:
@ViewChild('cmp1') cmp1: CdkVirtualScrollViewport;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.