angular - 如果 MatSelctionList,如何获取屏幕上可见的项目数量?
问题描述
我想在代码中知道屏幕上的材料选择列表中显示了多少项目。
我尝试使用:
@ViewChild(MatSelectionList) matSelectionList: MatSelectionList;
但是我没有看到任何带有该信息的变量或函数。有没有人有类似的问题?
这样做的目的很简单:我的应用程序中有文件资源管理器,当我升级时,我需要知道有多少元素。
解决方案
这里是<mat-selection-list>
https://run.stackblitz.com/api/angular/v1?file=src%2Fapp%2Flist-selection-example.ts的官方文档
<mat-selection-list #shoes>
<mat-list-option *ngFor="let shoe of typesOfShoes">
{{shoe}}
</mat-list-option>
</mat-selection-list>
<p>
Options selected: {{shoes.selectedOptions.selected.length}}
</p>
推荐阅读
- html - 使用 Nuxt.js 从单个 HTML 页面预渲染多个页面
- node.js - 如何从 PHP 文件运行 node.js 文件
- windows - 在 Windows 上的 bash 中清除 PowerShell 控制台
- angular - 规范化ngrx中的嵌套响应
- reactjs - .push() 在重新访问页面时创建重复的表过滤器下拉列表
- android - 我在我的 Android 应用程序中的 Google 地图上显示用户的当前位置时遇到问题。谁能告诉我我需要用我的代码做什么
- python - 在 Python 中查找单词的第一个元音
- kubernetes - 通过 Helm 安装 jFrog Artifactory,安装错误
- c++ - Qt 模型测试,removeRows
- rust - 使用 ?内部封闭