angular - Angular 2 稍后将表单控件转换为表单组
问题描述
我有一个表单数组,其中包含一个名为“foreground”的控件,该控件以 null 开头:
(<FormArray>this.myForm.get('rooms')).push(this.fBuilder.group({
id: [element.id, [Validators.required]],
background: null,
foreground: null,
}));
但是我怎样才能把它变成一个表单组,后面有字段呢?我试过这个:
room.controls.foreground(this.fBuilder.group({
foregroundImageID: [null, [Validators.required]],
foregroundImagePath: [null, [Validators.required]],
foregroundXPosition: [null, [Validators.required]],
foregroundYPosition: [null, [Validators.required]]
}));
解决方案
像这样构建你的表单
(<FormArray>this.myForm.get('rooms')).push(this.fBuilder.group({
id: [element.id, [Validators.required]],
background: null,
foreground: this.fBuilder.array([]),
}));
现在,前台作为数组工作,您可以将元素推入前台
推荐阅读
- python - 在pycharm中使用C++ dll
- django - 根据变化的值过滤 Django 中的查询集
- php - 如何在 CodeIgniter 中使用 CSV 导入库?
- angular - 子路线未正确显示角度
- gremlin - 查询每个连接顶点的边数
- keras - CNN 中的模型损失分布
- bash - 如何分别对文件夹内的所有文件运行 awk 然后将输出合并为一个?
- angular - 预期的间谍导航已使用 [ [ '/ProjectData/MasterSequence' ] ] 调用,但从未调用过
- ansible - Ansible 使用“原始”模块从一台主机 scp 到主机列表(最好在清单中)
- c# - 当您有两个日期时如何清除数据库?