Angular CDK-VIRTUAL-SCROLL-VIEWPORT不起作用
我有一个与CDK-Virtual-Scroll-viewPort的组件,该组件显示卡
scrolling.component.ponent.html
<cdk-virtual-scroll-viewport (scrolledIndexChange)="scrolledEnd()" class="list-container" [itemSize]="50">
<app-coin *cdkVirtualFor="let coin of coins; trackBy: trackByFn" [coin]="coin"
class="list-group-item state-item">
</app-coin>
</cdk-virtual-scroll-viewport>
scrolling.component.component.ts
export class ScrollingComponent {
@ViewChild(CdkVirtualScrollViewport) private viewport: CdkVirtualScrollViewport;
public coins: ICoin[] = [GOLD_SALE_COIN, PRESALE_COIN, GOLD_SALE_COIN, SILVER_COIN, GOLD_COIN, GOLD_SALE_COIN];
constructor(private cd: ChangeDetectorRef) {
}
public trackByFn(index: number, item: ICoin): number {
return item.id;
}
public scrolledEnd(): void {
if(this.viewport.getRenderedRange().end === this.coins.length) {
this.coins.push(...[GOLD_SALE_COIN, PRESALE_COIN, GOLD_SALE_COIN, SILVER_COIN, GOLD_COIN, GOLD_SALE_COIN]);
this.cd.markForCheck();
}
}
}
i仅输出6张卡片,这些卡在数组
如何确保完成完成的那一刻,我添加了更多元素
I have a component with cdk-virtual-scroll-viewport which displays cards
scrolling.component.html
<cdk-virtual-scroll-viewport (scrolledIndexChange)="scrolledEnd()" class="list-container" [itemSize]="50">
<app-coin *cdkVirtualFor="let coin of coins; trackBy: trackByFn" [coin]="coin"
class="list-group-item state-item">
</app-coin>
</cdk-virtual-scroll-viewport>
scrolling.component.ts
export class ScrollingComponent {
@ViewChild(CdkVirtualScrollViewport) private viewport: CdkVirtualScrollViewport;
public coins: ICoin[] = [GOLD_SALE_COIN, PRESALE_COIN, GOLD_SALE_COIN, SILVER_COIN, GOLD_COIN, GOLD_SALE_COIN];
constructor(private cd: ChangeDetectorRef) {
}
public trackByFn(index: number, item: ICoin): number {
return item.id;
}
public scrolledEnd(): void {
if(this.viewport.getRenderedRange().end === this.coins.length) {
this.coins.push(...[GOLD_SALE_COIN, PRESALE_COIN, GOLD_SALE_COIN, SILVER_COIN, GOLD_COIN, GOLD_SALE_COIN]);
this.cd.markForCheck();
}
}
}
I only output 6 cards, which are defined in the array
How do I make sure that the moment I finish finishing, I have more elements added
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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