如何解决使用 patchValue 更新表单数组中的值
我正在尝试使用 patchValue 更新 formArray 中的值,但在某些情况下,例如:
表单数组:
0: {id: 12,start_time: "17:11",end_time: "17:41",name: "AUB Medical Center"}
1: {id: 15,start_time: "17:58",end_time: "18:03",name: "Sanayeh"}
我想更改对象 1 中的 start_time。
所以我需要使用这个:this.locationForm.patchValue(newValueOfStartTime);
这里我不能给 patchValue 分配我想改变的对象的 id 和参数!
有什么建议吗?
解决方法
赋值如下
this.locationForm[index].get('start_time').setValue(newValueOfStartTime);
,
那个!
this.locationForm.at(index).patchValue({
start_time: newValueOfStartTime
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。