【发布时间】:2021-05-04 04:21:05
【问题描述】:
我正在使用 Angular 8。在这个我有一个类似的 api
{
"no": "s01",
"id": 1,
"details_id": {
"install": "Y"
"unitprice": "100.000000000000000",
"weight": "1.000000000000000"
},
"qty": 1,
"remarks": "ok"
}
我必须使用 angular 修补下面这种格式的数据
{
"Header_img": null,
"details": [
{
"install": "",
"remarks":""
"del_details": [
{
"qty": "",
"unitprice":"",
"weight": ""
}
]
}
]
}
ngOnInit(): void {
this.Form = this.fb.group({
Header_img: [],
podetails: this.fb.array([this.addpodetailsGroup()])
});
}
addpodetailsGroup() {
let group= new FormGroup({
install: new FormControl(''),
d_details: this.fb.array([
this.d_detailsGroup()
])
}
)
return group}
d_detailsGroup(): FormGroup {
return this.fb.group({
qty: new FormControl(''),
"unitprice": new FormControl(''),
"weight": new FormControl(''),
});
}
补丁功能
getdDetails(){
let id = this.iddata
this.dataService.getdetails(id)
.subscribe((results) => {
let datas = results["data"];
this.dList = datas
})
}
getdetailsForQuantity(data){
let id = data.id
console.log('id value data getdetailsForQuantity',id)
this.dataService.getdetailsfor(id)
.subscribe((result: any) => {
this.install = result.details_id.installationrequired
this.unitprice = result.details_id.unitprice
this.form.patchValue({
details:[{
install: this.install
d_details: this.unitprice
}]
})
})
}
如何修补表单数组中的数据?使用响应式表单如何修补来自后端的数据格式不准确的数据以发送要提交的数据,但我必须修补并以嵌套数组格式传递数据。
【问题讨论】:
标签: angular typescript angular8 angular-reactive-forms formarray