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方法来调整高度。

相关内容

热门资讯

透视有挂"hhpok... 透视有挂"hhpoker辅助挂是真的吗"真是真的是有辅助神器(哔哩哔哩)1、该软件可以轻松地帮助玩家...
透视解谜"智星德州插... 透视解谜"智星德州插件最新版本更新内容详解"切实真的有辅助脚本(哔哩哔哩)1、透视解谜"智星德州插件...
透视辅助"wepok... 透视辅助"wepoker底牌透视"都是是真的辅助神器(哔哩哔哩)1、用户打开应用后不用登录就可以直接...
透视辅助"wepok... 透视辅助"wepoker透视脚本苹果版"一直是有辅助方法(哔哩哔哩)1)wepoker透视脚本苹果版...
透视透视"wepok... 您好,wepoker能不能透视这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302...
透视解谜"wejok... 透视解谜"wejoker私人辅助软件"真是是真的辅助插件(哔哩哔哩)1、wejoker私人辅助软件免...
透视解迷"wpk透视... 透视解迷"wpk透视怎么安装"好像真的是有辅助器(哔哩哔哩)1、下载好wpk透视怎么安装正确养号方法...
透视总结"aapok... 透视总结"aapoker怎么拿好牌"果然是真的辅助工具(哔哩哔哩)1、aapoker怎么拿好牌辅助器...
透视总结"htx矩阵... 透视总结"htx矩阵wepoker辅助"一直是有辅助脚本(哔哩哔哩)该软件可以轻松地帮助玩家将htx...
透视推荐"hhpok... 透视推荐"hhpoker到底可以作必弊吗"切实是真的辅助神器(哔哩哔哩)1、hhpoker到底可以作...