如果使用MatSelctionList,如何获得多少项目在屏幕上可见?

问题描述 投票:0回答:1

我不希望在代码中知道屏幕上的物料选择列表中显示了多少个项目。我试图使用

    @ViewChild(MatSelectionList) matSelectionList: MatSelectionList;

但是我没有看到带有该信息的任何变量或函数。有人有类似的问题吗?这样做的目的很简单:我的应用程序中有文件浏览器,当我升级时,我需要知道那里有多少个元素。

angular typescript list selection material
1个回答
0
投票

这里是<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>
© www.soinside.com 2019 - 2024. All rights reserved.