【发布时间】:2018-05-23 15:24:42
【问题描述】:
我正在使用 ng2FileUpload 创建拖放以进行上传,但我也希望允许用户单击拖放区域以打开文件对话框。
考虑到我有这个输入:
<input type="file" ng2FileSelect [uploader]="uploader" style="display: none" />
如何从 Angular 4 打字稿代码中显示文件对话框?
【问题讨论】:
标签: angular typescript
我正在使用 ng2FileUpload 创建拖放以进行上传,但我也希望允许用户单击拖放区域以打开文件对话框。
考虑到我有这个输入:
<input type="file" ng2FileSelect [uploader]="uploader" style="display: none" />
如何从 Angular 4 打字稿代码中显示文件对话框?
【问题讨论】:
标签: angular typescript
我已经能够这样做了:
模板:
<input type="file" ng2FileSelect [uploader]="uploader" hidden #fileInput />
角度组件:
@ViewChild('fileInput') fileInput:ElementRef;
public openFileDialog():void {
let event = new MouseEvent('click', {bubbles: false});
this.fileInput.nativeElement.dispatchEvent(event);
}
【讨论】: