angular - 如何在标签中显示所选文件而不是角度6中的输入标签
问题描述
我应该在标签标签中显示选定的文件名,而不是在输入标签中显示。你能帮我实现这一目标吗?提前致谢
我的代码如下所示,
<div *ngFor='let item of list; let i = index'>
<input #fileInput type="file" />
<button type="button" (click)="fileInput.click()">trigger</button>
<button type="button" (click)="reset(fileInput, i)">Reset</button>
</div>
我尝试将输入标签更改为标签,但它不起作用。你能帮我实现它吗?提前致谢。
解决方案
试试这个代码。我希望它会对你有所帮助。
HTML:
<div>
<div>
<input #fileInput type="file" (change)="fileProgress($event)" />
<button type="button" (click)="fileInput.click()">trigger</button>
<button type="button" (click)="reset(fileInput, i)">Reset</button>
</div>
<span *ngIf="fileName">{{fileName}}</span>
</div>
TS:
fileProgress(fileInput: any) {
let file = fileInput.target.files[0];
this.fileName = file.name;
console.log(this.fileName)
}
推荐阅读
- excel - Windows 更新后 Excel 宏不起作用 - Office 365
- python - 在 Python 中编写 Discord 机器人 - 在 Heroku 上托管我的机器人时遇到了一些问题
- c# - 如何创建一个采用映射的通用列表和字符串参数的方法?
- go - 如何检查2个目录是否在同一个分区上?
- c# - 接口和异步实践
- java - 当我检测到未接来电而不是当呼叫被拒绝时如何做某事
- python - 说明人工神经网络层
- angular - 重新加载时 Mat-tab 不在底层
- autodesk-forge - 如何从 zip 打开 .rvt 文件?
- azure - Azure 数据共享资源在尝试从 terraform 预配时抱怨标记应全部为小写