AngularMaterial虚拟滚动高度不正确调整
创始人
2024-10-28 11:01:54
0

在使用Angular Material中的虚拟滚动功能时,当其中的内容数量发生变化时,高度可能无法正确地调整。解决方法是使用ViewChild来访问滚动条,然后在内容发生变化时手动调整高度。下面是一个示例代码:

HTML模板文件:


  
{{ item }}

组件类文件:

import { Component, ElementRef, ViewChild } from '@angular/core';
import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling';

@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.css']
})
export class MyComponent {
  @ViewChild('scrollViewport') scrollViewport: CdkVirtualScrollViewport;
  items: string[] = [];

  addItem() {
    this.items.push('new item');
    this.scrollViewport.checkViewportSize();
  }

  onScroll() {
    // do something
  }
}

在这个示例中,我们使用ViewChild来引用滚动条,然后在addItem方法中添加新项并手动调用checkViewportSize方法来调整高度。

相关内容

热门资讯

揭幕透视!wepoker网页版... 揭幕透视!wepoker网页版透视方法,微乐自建房辅助可信吗,技法教程(有挂助手)-哔哩哔哩一、we...
解密透视!来玩app破解版,微... 解密透视!来玩app破解版,微乐小程序怎么挂脚本,绝活儿教程(有挂方法)-哔哩哔哩1、来玩app破解...
总结透视!cloudpoker... 总结透视!cloudpoker作弊,微信小程序微乐房间怎么辅助,教程书教程(有挂详情)-哔哩哔哩cl...
推荐透视!aa poker辅助... 推荐透视!aa poker辅助,微信小程序 微乐陕西挖坑 外挂,阶段教程(有挂详细)-哔哩哔哩1、玩...
详细透视!poker worl... 详细透视!poker world辅助器,微乐自建房怎么提高胜率,技法教程(有挂教学)-哔哩哔哩1、实...
详情透视!如何下载wepoke... 详情透视!如何下载wepoker安装包,手机微乐小程序破解器,教程书教程(有挂猫腻)-哔哩哔哩详情透...
科普透视!werplan怎么作... 科普透视!werplan怎么作弊,微信小程序微乐破解填大坑,指引教程(确实有挂)-哔哩哔哩所有人都在...
了解透视!wepoker免费脚... 了解透视!wepoker免费脚本咨询,微乐小程序怎么挂脚本,诀窍教程(有挂分享)-哔哩哔哩了解透视!...
普及透视!哈糖大菠萝助手,微乐... 普及透视!哈糖大菠萝助手,微乐自建房辅助工具,指引教程(确实有挂)-哔哩哔哩一、哈糖大菠萝助手游戏安...
了解透视!wepokerplu... 了解透视!wepokerplus万能挂,微乐自建房辅助工具2025在哪,积累教程(存在有挂)-哔哩哔...