【发布时间】:2019-07-16 14:06:53
【问题描述】:
我有一个这样定义的表单:
this.entityForm = this.fb.group({
// Searching ID
search: this.fb.group({
procedures: '',
areas: '',
entities: '',
versions: '',
}),
// Entity
entity: this.fb.group({
// Id
name: '',
version: '',
// Data Source
cobolFileName: '',
cobolUri: '',
hostDbUri: '',
hostDbTable: '', // Format (schema.table)
wsUri: '',
// Historice
historicizeStrategy: '',
pwx: '',
// Rows
rows: this.fb.array([this.newRow()])
})
});
当我这样做时:
let a = this.entityForm.get('entity');
let b = this.entityForm.get('entity.rows');
console.log(a.value);
console.log(b.value);
答案是:
{
cobolFileName: "NAME OF FILE"
cobolUri: "mainframe"
historicizeStrategy: "START_END_VALIDITY"
hostDbTable: null
hostDbUri: null
name: "GRZ_PERS"
pwx: false
rows: Array(0)
length: 0
__proto__: Array(0)
version: 1
wsUri: null
__proto__: Object
}
{
0: {name: "Column_2", datatype: "INTEGER", defaultValue: "", key: false, masked: true, …}
1: {name: "Column_1", datatype: "INTEGER", defaultValue: "", key: false, masked: true, …}
length: 2
__proto__: Array(0)
}
我想将 a.value 发送到后端,但是对于某些行数组长度为 0 但数组已满,我们如何在第二个 console.log 中看到?
谢谢
【问题讨论】:
-
能否也分享一下 newRow() 方法!!
-
newRow():FormGroup{ return this.fb.group({ name: '', datatype: '', defaultValue: '', key: '', masked: '', size: ' ', pwx: '' }); }
-
如果有可能进行 stackblitz 之类的,我不知道我们可以如何帮助您,我的第一个想法可能是 formarray 被禁用但我不认为是因为这个跨度>
标签: angular angular6 angular-reactive-forms