这是我的数据结构
class myObject
{
name: string;
notes: string[];
}
我旨在创造一个反应形式组要绑定的名称和所有音符(每个音符有个别控制)。
this.formGroup = this.formBuilder.group
({
name: new FormControl(getName()), //returns a string
notes: this.formBuilder.array(getNotes()) //returns a string array
});
<div [formGroup]="formGroup">
<input formControlName="name">
<div formArrayName="notes">
<div *ngFor="let note of formGroup.controls.notes.controls; let i=index">
<div formGroupName="{{ i }}">
<input formControlName="{{ i }}"> // bind array element to formcontrol
</div>
</div>
</div>
</div>
如何将“财产少”字符串数组的formcontrol每个字符串绑定?我打:Error错误:无法与路径找到控制: '笔记 - > 0 - > 0'
感谢所有帮助提前!
设法实现使用上面:
<div [formGroup]="formGroup">
<input formControlName="name">
<div formArrayName="notes">
<div *ngFor="let note of formGroup.controls.notes.controls; let i=index">
<div formGroupName="{{ i }}"> //remove this tag
<input formControlName="{{ i }}">
</div>
</div>
</div>
</div>
简单地删除“DIV formGroupName =‘{{I}}’”标记,因为它不是一个嵌套的数据结构。