When attempting to set the value for a sort object with specific type and format, I encountered an issue where it was not being rendered. Below is my code snippet using patch to set the value:
let arr = <FormArray>this.myForm.controls.users;
arr.controls[0].patchValue({ name: this.test[0].name, displayOrder: this.test[0].displayOrder,type:this.test[0].sort.type});
Here is the corresponding HTML code:
<fieldset formGroupName="sort">
<tr><td>type:</td><td><input type="text" formControlName="type"></td></tr>
<tr><td>format:</td><td><input type="text" formControlName="format"></td></tr>
</fieldset>
You can find the full code at the following URL:
Additionally, here is the JSON format of the data involved:
[
{
"name": "manu",
"displayOrder": 1,
"sort": {
"type": "first",
"format": "normal"
},
"data": [
{
"category": "electrical",
"name": "ele"
}
]
},
{
"name": "divya",
"displayOrder": 1,
"sort": {
"type": "second",
"format": "center"
},
"data": [
{
"category": "tech",
"name": "ea_tcv"
}
]
}
]
I have included a screen shot to illustrate the issue of setting values dynamically while selecting from a select box. You can view the screenshot here.
If anyone has insights on how to resolve this issue and render the values into the sort object (specifically type and format) dynamically, please let me know.