You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取ngx-awesome-uploader中用户选择的项目数量?

ngx-awesome-uploader 选中项目数量统计支持说明

ngx-awesome-uploader 完全支持统计用户选中的项目数量,有两种常用实现方式:

  • 直接读取组件绑定的文件数组长度
    组件允许通过 [files] 属性绑定一个数组,所有选中的项目会自动同步到这个数组中,直接获取数组的 length 属性就能得到选中数量。

  • 监听文件选中事件获取数量
    组件提供 filesSelected 事件,当用户完成文件选择后会触发该事件,回调参数包含当前选中的所有项目列表,从列表中读取 length 即可统计数量。

代码示例

模板部分

<ngx-awesome-uploader
  [files]="selectedItems"
  (filesSelected)="handleFilesSelected($event)"
></ngx-awesome-uploader>

组件类部分

import { Component } from '@angular/core';

@Component({
  selector: 'app-upload-demo',
  templateUrl: './upload-demo.component.html'
})
export class UploadDemoComponent {
  selectedItems: any[] = [];

  handleFilesSelected(selectedFiles: any[]) {
    // 统计选中数量
    const count = selectedFiles.length;
    console.log(`当前选中 ${count} 个项目`);
  }

  // 随时获取选中数量的方法
  getSelectedItemCount(): number {
    return this.selectedItems.length;
  }
}

内容的提问来源于stack exchange,提问作者Assustadora de Código

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 16:58:59