我使用角度为6的反应形式。该反应形式包含一个称为FormGroup
的{{1}},即instruments
。
我收到了以下信息:表格数组为无效,但数组的所有组件均为FormArray
。
有什么问题?
初始化表格
valid
initializeForm(laboratory) {
this.laboratoryForm = this.formBuilder.group({
laboratoryId: [laboratory && laboratory.Id],
clientId: [this.currentUserClientId],
name: [laboratory && laboratory.Name, [Validators.required, Validators.maxLength(50)]],
code: [laboratory && laboratory.Code, [Validators.required, Validators.maxLength(5)]],
description: [laboratory && laboratory.Description, [Validators.required, Validators.maxLength(1000)]]
});
if (laboratory && laboratory.LaboratoryInfoSystem) {
let laboratoryInfoSystemFormGroup = this.formBuilder.group({
id: [laboratory.LaboratoryInfoSystem.Id],
description: [laboratory.LaboratoryInfoSystem.Description, [Validators.maxLength(1000)]],
model: [laboratory.LaboratoryInfoSystem.Model, [Validators.required, Validators.maxLength(50)]],
name: [laboratory.LaboratoryInfoSystem.Name, [Validators.required, Validators.maxLength(50)]],
lis_connection: this.formBuilder.group({
id: [laboratory.LaboratoryInfoSystem.LaboratoryInfoSystemConnection.id],
connection: [laboratory.LaboratoryInfoSystem.LaboratoryInfoSystemConnection.Connection, [Validators.required, Validators.maxLength(1000)]],
connectionTypeId: [laboratory.LaboratoryInfoSystem.LaboratoryInfoSystemConnection.ConnectionTypeId, [Validators.required]],
username: [laboratory.LaboratoryInfoSystem.LaboratoryInfoSystemConnection.Username, [Validators.maxLength(100)]],
password: [laboratory.LaboratoryInfoSystem.LaboratoryInfoSystemConnection.Password, [Validators.maxLength(100)]]
})
});
this.laboratoryForm.addControl('laboratoryInfoSystem', laboratoryInfoSystemFormGroup);
}
if (laboratory && laboratory.Instruments) {
let formInstrumentsArray = laboratory.Instruments.map(function (instrument) {
return this.getInstrumentForm(instrument.Model, instrument.Name, instrument.Description, instrument.InstrumentConnection);
}.bind(this));
this.laboratoryForm.addControl('instruments', this.formBuilder.array(formInstrumentsArray));
}
}
功能
getInstrumentForm
}
答案 0 :(得分:1)
请查看stackblitz-demo。我将从以下内容开始,然后,如果看到它已经解决了错误。
您具有以下内容:
let formInstrumentsArray = laboratory.Instruments.map(function(instrument) {
return this.getInstrumentForm(instrument.Model, instrument.Name, instrument.Description, instrument.InstrumentConnection);
}.bind(this));
缺少使映射的工具成为表单数组内的表单控件的缺失。在我的示例中,我有这个:
const toppingsFGs = toppings.map(topping => this.fb.group(topping));
对于您来说,您需要弄清楚预处理,然后将其传递到映射的结果到组中。
let formInstrumentsArray = laboratory.Instruments.map(function(instrument) {
return this.getInstrumentForm(instrument.Model, instrument.Name, instrument.Description, instrument.InstrumentConnection);
}.bind(this));
let final = formInstrumentsArray.map(instrument => this.fb.group(instrument));