Reputation: 145
I tried to set the value to sort object having the value type and format. but it's not rendered. below is my code to set value using patch
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});
Below is the 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>
Below is the code URL
Below is the json format
[
{
"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"
}
]
}
]
Below i have attached the screen-shot, i am unable to set the value to type and format when i am selecting select box dynamically. below is the screen shot.
any body help on this to render the value dynamically into sort object(type,format) while selecting select box?
working now, but got typo error: below screen shot
Upvotes: 1
Views: 37
Reputation: 6311
try this
const sorts = this.myForm.get(['users', 0, 'sort']) as FormGroup;
sorts.patchValue({type : 'your_value' , format :'your_value'})
Upvotes: 1