Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.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
Javascript 角6嵌套阵列_Javascript_Angular_Typescript - Fatal编程技术网

Javascript 角6嵌套阵列

Javascript 角6嵌套阵列,javascript,angular,typescript,Javascript,Angular,Typescript,我正在尝试创建一个表单,通过使用角度反应表单单击“+”生成一个字段数组。然而,当我尝试在子组件中使用[formControlName]=“index”时,它不起作用 首先,它说formControlName应该有一个带有FormGroup的父级,我传递了它并添加了它。现在它说,找不到具有未指定名称属性的控件名。在Angular docs中,据说由于没有名称,因此可以将FormArray与[formControlName]和索引一起使用 这就是我所拥有的 我已经解决了您的问题。您需要在此处传递fo

我正在尝试创建一个表单,通过使用角度反应表单单击“+”生成一个字段数组。然而,当我尝试在子组件中使用
[formControlName]=“index”
时,它不起作用

首先,它说
formControlName
应该有一个带有
FormGroup
的父级,我传递了它并添加了它。现在它说,
找不到具有未指定名称属性的控件名
。在Angular docs中,据说由于没有名称,因此可以将FormArray与
[formControlName]
和索引一起使用

这就是我所拥有的
我已经解决了您的问题。您需要在此处传递formGroupName:

<app-site-form-feature 
       *ngFor="let feature of features.controls; let last = last; let index = index; let first = first" [formGroupName]="index"
        [last]="last" [index]="index" [first]="first"
         (addFeature)="addFeature()" (removeFeature)="removeFeature(index, first, last)">
</app-site-form-feature>

您也可以参考本指南:

为什么您的表单中有
novalidate
但您有验证器?您的问题是您有一个表单,并且您正在将这些索引指定为表单的一部分,而这些索引并不存在。您必须将它们添加到此处。fb.group({…})作为文本添加数字1:''作为属性,并且在您第一次按+符号时它将起作用…现在您必须了解如何将所有这些索引动态添加到fb.group对象
<div class="row no-gutters form-group">
  <input type="text" class="form-control px-2 col-10">
  <span class="btn btn-outline-danger" (click)="removeFeature.emit(index, first, last)">-</span>
  <span class="btn btn-success" *ngIf="last" (click)="addFeature.emit($event,index)">+</span>
</div>