I tried to render the cat_name dynamically by selecting the select box. but i am not able the render the cat_name by using the patchValue. Below is my code to render the sub formArray.
By selecting the select box using change event i got the firstname based on value i have filter the json array and i got particular formarray.
It having the data formArray i tried to render the cat_name while selecting the select box but i am not getting. Below is my code
selectarch(cat){
this.test=this.users.filter(data =>data.firstname === cat.target.value);
let arr = <FormArray>this.myForm.controls.users;
arr.controls[0].patchValue({firstname:this.test[0].firstname,lastname:this.test[0].lastname,street:this.test[0].street});
let arr2 = <FormArray>this.myForm.controls.users[0].data;
arr2.controls[0].patchValue({cat_name:this.test[0].data[0].cat_name});
}
<select (change)="selectarch($event)">
<option>Select</option>
<option [value]="res.firstname" *ngFor="let res of users">{{res.firstname}}</option>
</select>
Below is my CODE URL CODE URL
Below is json users array.
users = [ { "firstname": "ramu", "lastname": "mothukuri", "city": "chennai", "street": "ramu sivan koiil street", "pin": "600024",
"data":[{"cat_id":"1","cat_name":"yyy","category":"rrr"},{"cat_id":"2","cat_name":"zzz","category":"222"}] },
{ "firstname": "ravi", "lastname": "mothukuri", "city": "chennai", "street": "ravi sivan koiil street", "pin": "600024","data":[{"cat_id":"1","cat_name":"ddd","category":"aaa"},{"cat_id":"2","cat_name":"aa","category":"333"}] },
{ "firstname": "manu", "lastname": "mothukuri", "city": "chennai", "street": "manu sivan koiil street", "pin": "600024","data":[{"cat_id":"1","cat_name":"jjj","category":"999"},{"cat_id":"2","cat_name":"bbb","category":"666"}] }
]