angular - Angular:如何使用 *ngFor 在 Firebase 存储中循环图像文件
问题描述
我正在构建一个具有图像上传功能的网络应用程序。
我可以成功地将图像上传到名为“uploads”的 Firebase 存储文件夹如何使用 *ngFor 在 HTML 上的“上传”文件夹中显示图像?我正在使用 AngularFire2,Angular 6。
upload() {
const file = this.selectedFiles.item(0);
this.selectedFiles = undefined;
this.currentFileUpload = new FileUpload(file);
this.uploadService.pushFileToStorage(this.currentFileUpload, this.progress);
}
public saveFileData(fileUpload: FileUpload) {
this.db.list(`${this.basePath}/`).push(fileUpload);
}
解决方案
如果您使用 FileList 对象来保存您的文件,您可以执行类似的操作。
<ul *ngIf="selectedFiles">
<li *ngFor="let file of selectedFiles">
<img src="URL.createObjectURL(file)">
</li>
</ul
我不确定您为什么将 this.selectedFiles var 设置为未定义,我认为您必须将图像文件放在 component.ts 中的某个位置
使用 FileList obj 或 File[] 从 db 获取要显示的图像到 component.ts 后,您可以使用 component.html 中的上述代码来显示它们。
推荐阅读
- spring-boot - 如何将 GlobalMethodSecurityConfiguration 迁移到 Reactive Spring?
- python - 获取布尔值数组的问题
- python - 有没有办法在命名新创建的文件时使用导入文件的名称?
- c++ - 如何在 QT 中使用 libraw?
- ios - Swift UICollectionView 在点击时显示/隐藏项目
- elasticsearch - kibanaa 中的断路异常
- csv - symfony 无法导出带有日期时间数据的 csv
- laravel - 如何在子域中托管后修复 laravel 应用程序中的 403 Forbidden 错误
- javascript - Javascript:如何在没有 ID 和 Class 的情况下向元素添加类?
- python - ModuleNotFoundError:未找到该模块的规范