angular - 无法修补空白表单数组
问题描述
我有一个表格:
this.myForm = this.fBuilder.group({
speeches: this.fBuilder.array([])
});
然后稍后我想用来自另一个组件的外部阵列来修补整个演讲阵列。示例数据:
newData = [{id: "wavesurfer_mt87bwp5cyi", start: 0.8766667991737204, duration: 2.006666969971786, characterId: 0},
{id: "wavesurfer_glxyt1be2js", start: 4.0033339384320845, duration: 2.2600003415961307, characterId: 1}]
我想像这样修补它:
this.myForm.controls.speeches.patchValue(newData);
但是 Angular 没有将空白数组修改为我想要的对象数组,怎么会?我必须始终将每个属性作为适当的表单控件吗?我不需要它,因为这些值永远不会在实际的表单字段中使用。
解决方案
如果您只是想针对 formControl“演讲”存储值数组,则不需要为此使用 FormArray。
this.myForm = this.fBuilder.group({
speeches: [[]]
});
this.myForm.controls.speeches.patchValue(newData);
推荐阅读
- docker - GitHub Docker 操作拉取请求分支
- google-chrome-extension - LocalStorage 在我的 chrome 扩展中不起作用
- summernote - Summernote 从 php 中获得很多价值
- node.js - 通过 Google Cloud 构建触发器部署“sh: 1: jest: Permission denied”
- pandas - 按最后一行的百分比选择列索引
- spring - Spring:@Autowired 注释 - 在哪里查看实际更改?
- excel - 在vba excel中循环
- reactjs - 如何解决 useEffect 中的依赖关系问题?
- python - 如何将pygame中的多个图像添加到网格上?
- google-cloud-platform - 运行 gcloud 命令时,我收到“错误:可达性检查失败”。