Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何在角度(2/4)中使用多个ViewChild元素_Angular_File Upload_Angular2 Forms - Fatal编程技术网

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
   }
}