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