我无法在按钮单击时添加新的文本字段
这是我累了的代码,
主页.ts
constructor() {
this.myForm = this._fb.group({
md: false,
mdNames: this._fb.group({
uid: "",
_rev: "",
type: "i_org_docs_ref",
name: "MARINE1",
details: "Material declaration",
details_array: this._fb.array([]),
cdt: ""
}),
});
}
addClicked() {
const control2 = <
FormArray( < FormGroup > this.myForm.controls['mdNames']).controls['details_array']
control2.push(this._fb.group({
mdTextBox: "",
}));
}
主页.html
<div formControlName="mdNames">
<div formArrayName="details_array">
<ion-list *ngFor="let obj of myForm.controls.details_array.controls; let i=index">
<div [formGroupName]="i">
<ion-item no-lines>
<button
ion-button
color="dark"
clear
icon-only
item-end
class="deleteBtn"
(click)="deleteOrgItemClicked(i)">
<ion-icon name="ios-trash"></ion-icon>
</button>
<ion-input
formControlName="mdTextBox"
type="text"
class="textFields"
placeholder="Type details">
</ion-input>
</ion-item>
</div>
</ion-list>
<ion-item>
<button
(click)="addClicked()"
class="addBtn">
Add documents
</button>
</ion-item>
</div>
</div>
我想显示details_array的值,但它显示此错误: No value accessor for form control with name: 'mdNames'
请帮助我在哪里犯错?