[英]Patchvalue in angular form
I my angular application, i am using angular dynamic form in which i am patching value with some json. 我的角度应用程序,我正在使用角度动态形式,其中我用一些json修补值。
data =
{
firstName:"Eliseo",
lastName:"Plunker",
myArray:
[
{
emailAddress:"eliseo@plunker.com",
brave:"solid"
},
{
emailAddress:"eliseo@plunker.org",
brave:"great"
}
]
}
Patchvalue function: 拍值函数:
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);
}
Here in this function, i want to patch only the myArray
values and not the firstName
and lastName
. 在此功能中,我只想修补
myArray
值,而不是firstName
和lastName
。
I have tried with this.data.myArray 我已经尝试过this.data.myArray
this.form.patchValue(this.data.myArray);
But it doesn't work. 但这是行不通的。
The working stackblitz : https://stackblitz.com/edit/angular-x4a5b6-wztvq9 工作中的stackblitz : https : //stackblitz.com/edit/angular-x4a5b6-wztvq9
Click over Fill Form button in the above demo to get the patched values in the form.. 在上面的演示中单击“ 填写表单”按钮,以获取表单中的修补值。
Kindly help me to patch only the myArray
value and leave others empty.. 请帮助我仅修补
myArray
值,并将其他值留空。
Try this to patch myArray values 试试这个补丁myArray值
this.form.patchValue({
'myArray' : this.data.myArray
});
Hope this helps!! 希望这可以帮助!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.