Angular Can';t修补空白表单数组
我有一张表格:Angular Can';t修补空白表单数组,angular,Angular,我有一张表格: this.myForm = this.fBuilder.group({ speeches: this.fBuilder.array([]) }); 然后稍后我想用另一个组件的外部数组来修补整个演讲数组。示例数据: newData = [{id: "wavesurfer_mt87bwp5cyi", start: 0.8766667991737204, duration: 2.006666969971786, characterId: 0
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);
然而,角度并没有修改空白数组到我想要的对象数组,为什么?必须始终将每个属性作为适当的窗体控件吗?我不需要这样做,因为这些值永远不会在实际的表单字段中使用。
如果您只是想针对formControl“Speechs”存储值数组,则不需要为此使用FormArraythis.myForm = this.fBuilder.group({
speeches: [[]]
});
this.myForm.controls.speeches.patchValue(newData);