Angular 如何在角度(2/4)中使用多个ViewChild元素
我已经按照上传单个文件和它的工作良好 现在我想根据数组Angular 如何在角度(2/4)中使用多个ViewChild元素,angular,file-upload,angular2-forms,Angular,File Upload,Angular2 Forms,我已经按照上传单个文件和它的工作良好 现在我想根据数组documentTypes[]中的元素数量上传动态文件数量 我的HTML: <div *ngFor="let item of documentTypes ;let i=index"> <input #fileInput[i] type="file" #select name="document[{{i}}]" /> </div> 提交功能: onSubmit = function (docs)
documentTypes[]
中的元素数量上传动态文件数量
我的HTML:
<div *ngFor="let item of documentTypes ;let i=index">
<input #fileInput[i] type="file" #select name="document[{{i}}]" />
</div>
提交功能:
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
}
}
onSubmit=函数(文档){
对于(var i=0;i
如有任何建议,我们将不胜感激。
@ViewChild
装饰师仅限一名儿童使用。要获取子对象数组,您需要使用@ViewChildren
尝试帮助其他人。这就是stackoverflow的想法。你需要分享你的知识。
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
}
}