我的 Angular 应用程序,我正在使用 Angular 动态形式,其中我用一些 json 修补值。
data =
{
firstName:"Eliseo",
lastName:"Plunker",
myArray:
[
{
emailAddress:"eliseo@plunker.com",
brave:"solid"
},
{
emailAddress:"eliseo@plunker.org",
brave:"great"
}
]
}
补丁值函数:
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);
}
在此函数中,我只想修补 myArray
值,而不是 firstName
和 lastName
。
我尝试过this.data.myArray
this.form.patchValue(this.data.myArray);
但是这不起作用。
工作堆栈 Blitz :https://stackblitz.com/edit/angular-x4a5b6-wztvq9
点击上面演示中的填写表单按钮即可获取表单中的修补值。
请帮我只修补 myArray
值并将其他值留空..
最佳答案
尝试使用此方法来修补 myArray 值
this.form.patchValue({
'myArray' : this.data.myArray
});
希望这有帮助!!
关于javascript - Angular 形式的补丁值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53278927/