我尝试将值设置为子组但却出错。下面是我的代码
let dataArr = new FormArray([]);
dataArr.push(new FormGroup({
'name': new FormControl(this.users[0].data[0].name),
'category': new FormControl(this.users[0].data[0].category)
}));
let formArr = <FormArray>this.myForm.controls.users;
formArr.push(this.fb.group({
name: this.users[0].name,
displayOrder: this.users[0].displayOrder,
sort: new FormGroup({
type:new FormControl(),
format: new FormControl()
}),
data: dataArr
}));
我尝试将值设置为具有类型和格式的对象。但无法设定。我的json对象是
[{"name":"manu","displayOrder":1,"sort":{
"type":"first","format":"normal"
},"data":[{"category":"electrical","name":"ele"}]},{"name":"divya","displayOrder":1,"data":[{"category":"tech","name":"ea_tcv"}]}]
表格的截图;
如何设置值以排序对象?
答案 0 :(得分:0)
我不是100%确定我正确理解你的问题,但是如果你需要为Sort对象设置值,你可以简单地将数据对象中的相应字段传递给FormControl构造函数:
{{1}}