1
我跟着https://devblog.dymel.pl/2016/09/02/upload-file-image-angular2-aspnetcore/上傳單個文件並且工作正常。如何在Angular中使用ViewChild上傳多個文件(2/4)
現在我想上傳基於數組中元素數量的動態數量documentTypes[]
。
我的HTML:
<div *ngFor="let item of documentTypes ;let i=index">
<input #fileInput[i] type="file" #select name="document[{{i}}]" />
</div>
我的TS:
@ViewChild("fileInput") fileInput: any[];
提交功能:
onSubmit = function (docs) {
for (var i = 0; i < this.documentTypes.length; i++) {
let fi = this.fileInput[i].nativeElement;
//This is not working. Here fileInput is undefined
}
}
任何建議將不勝感激。
非常感謝。它解決了我的問題:) –
嘗試對其他人有所幫助。這是stackoverflow的想法。你需要分享你的知識。 – be4code