我有这样一个表单,它包含一个表单组objform数组。
this.objform = this.fb.group({
val: null,
string: '',
arr: this.fb.array([null, null, null])
})
this.nestedform = this.fb.group({
arr: this.fb.array([this.objform, this.objform, this.objform]),
test1: null,
test2: ""
})我遇到了一个问题,当我setValue() of this.nestedform时,arr的值是数组中的最后一个obj。为什么会发生这种情况?我只是犯了个愚蠢的错误吗?
谢谢
如果你想看完整的例子,我有一个stackblitz 这里。
发布于 2019-10-19 10:35:03
您要将相同的对象分配给nestedForm中的数组。使用返回formGroup的函数
getGroup()
{
return this.fb.group({
val: null,
str: '',
arr: this.fb.array([null, null, null])
})
}并在创建窗体时使用
this.nestedform = this.fb.group({
arr: this.fb.array([this.getGroup(), this.getGroup(), this.getGroup()]),
test1: null,
test2: ""
})所以,您有一个不同的“对象”
https://stackoverflow.com/questions/58457822
复制相似问题