In my Angular project, I am utilizing an angular dynamic form where I am populating values using JSON.
data = {
firstName:"Eliseo",
lastName:"Plunker",
myArray:[
{
emailAddress:"<a href='/cdn-cgi/l/email-protection' class='__cf_email__' data-cfemail='1570797c66707a556579607b7e70673b767'>
[email protected]</a>",
brave:"solid"
},
{
emailAddress:"<a href='/cdn-cgi/l/email-protection' class='__cf_email__' data-cfemail='e7828b8e948288a7978b92889e8689d398895880'>[email protected]</a>",
brave:"great"
}
]
}
Function to patch values:
fillData() {
this.form = this.qcs.toFormGroup(this.questions);
for (let i=0;i<this.data.myArray.length;i++) {
this.addControls('myArray');
}
//Use patchValue
this.form.patchValue(this.data);
}
In the above function, I only want to update the values in myArray
and not firstName
or lastName
.
I attempted with this.data.myArray
this.form.patchValue(this.data.myArray);
However, it did not work as expected.
View the working stackblitz: https://stackblitz.com/edit/angular-x4a5b6-wztvq9
Click on the Fill Form button in the demo above to see the updated values in the form.
Please assist me in patching only the myArray
value and keeping others empty.