如何在另一个FormGroup内部的FormGroup内部访问FormArray?
我有一系列数据如下:
[
{
id: "1",
name: "task1",
taskForms: [
{
id: "8782",
name: "ProcedureComment",
sortOrder: null,
description: "Comment for 'Procedure end / Suture' task",
label: null
},
{
id: "20",
name: "form20",
description: "form20 description",
label: "form20 lable"
}
]
},
{
id: "2",
name: "task2",
taskForms: [
{
id: "87822",
name: "ProcedureComment2",
sortOrder: null,
description: "Comment for 'Procedure end / Suture' task2",
label: null
},
{
id: "202",
name: "form202",
description: "form202 description",
label: "form202 lable"
}
]
}
];
我想将taskforms
转换为formarray()
。
我是否必须将任务标记为formgroup
,然后标记 taskforms 为formarray
?我该怎么做?
public formGroup = new FormGroup({
tasks: new FormControl([])
//==>> i need it first as FormControl then i want to convert it and write data inside.
});
我尝试了:
this.formGroup.setControl('tasks', this.formBuilder.group(tasks));
但是我无法正常工作。
I have an array of data as follows:
[
{
id: "1",
name: "task1",
taskForms: [
{
id: "8782",
name: "ProcedureComment",
sortOrder: null,
description: "Comment for 'Procedure end / Suture' task",
label: null
},
{
id: "20",
name: "form20",
description: "form20 description",
label: "form20 lable"
}
]
},
{
id: "2",
name: "task2",
taskForms: [
{
id: "87822",
name: "ProcedureComment2",
sortOrder: null,
description: "Comment for 'Procedure end / Suture' task2",
label: null
},
{
id: "202",
name: "form202",
description: "form202 description",
label: "form202 lable"
}
]
}
];
and I want to convert taskForms
to FormArray()
.
Do I have to mark tasks
as formGroup
and then mark taskForms
as FormArray
? How do I do this?
public formGroup = new FormGroup({
tasks: new FormControl([])
//==>> i need it first as FormControl then i want to convert it and write data inside.
});
I tried:
this.formGroup.setControl('tasks', this.formBuilder.group(tasks));
but I couldn't make it work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嵌套FormGroup中的FormArray
您只需使用
formBuilder
使您的生活更轻松:结果
加载数据
以加载您只需将对象映射到
value
成员所需的数据formControls
这是 stackblitz for您要测试/玩。
FormArray in Nested FormGroup
You can just use the
FormBuilder
to make your life easier:Result
Load the Data
To load the data you will just need to map your object to the
value
members of theFormControls
.Here's an example on Stackblitz for you to test/play with.