Javascript 如何将formArray添加到formGroup?

Javascript 如何将formArray添加到formGroup?,javascript,angular,typescript,angular-reactive-forms,Javascript,Angular,Typescript,Angular Reactive Forms,首先为我的英语道歉 我在尝试将数组字段添加到formGroup时遇到问题 我正在尝试使用push方法将formArray添加到我的rate formGroup中,我认为出现的错误是由于formControlName造成的 当我搜索和阅读问题时,它就在那里,但我无法解决它,有人能帮我吗 我创建了这个stackblitz,所以你可以看到它给我的错误 要使用FormArray,您需要了解以下内容: Need form group \

首先为我的英语道歉

我在尝试将数组字段添加到formGroup时遇到问题

我正在尝试使用push方法将formArray添加到我的rate formGroup中,我认为出现的错误是由于formControlName造成的

当我搜索和阅读问题时,它就在那里,但我无法解决它,有人能帮我吗

我创建了这个stackblitz,所以你可以看到它给我的错误


要使用FormArray,您需要了解以下内容:

                Need form group
                   \/\/\/
<form [formGroup]="rates">
    <input type="text" placeholder="credit_card" formControlName="credit_card" />
                       Need form array name
                          \/\/\/
    <div formArrayName="servicesRates" *ngFor="let item of rates.get('servicesRates').controls; let i = index;">
        <div [formGroupName]="i"> <-- this is important
            <input type="text" placeholder="id" formControlName="id" />
            <input type="text" placeholder="Servicio" formControlName="service" />
            <input type="text" placeholder="Price" formControlName="price" />
        </div>
    </div>
</form>
并添加新功能:

addField() {
   this.servicesRates = this.rates.get('servicesRates') as FormArray;
   this.servicesRates.push(this.servicesRates);
}

你真的需要找到一个toturial来了解formArray是如何工作的检查这个我必须检查什么?检查这个-已经做了更改-这个解决方案是最适合我的,也是我最了解的,非常感谢。尽管如此,我还是在控制台中发现了一个错误,超过了最大调用堆栈大小,根据addField的错误行,在添加字段时,还有另外两个错误:无法通过路径找到控件:“servicesRates->1->service”无法通过路径找到控件:“servicesRates->1->price”感谢您需要查看该子组件的一切
addField() {
   this.servicesRates = this.rates.get('servicesRates') as FormArray;
   this.servicesRates.push(this.servicesRates);
}