【发布时间】:2018-10-12 04:12:39
【问题描述】:
我正在尝试在数组中的表单上添加新的表单控件,但我遇到的问题是我总是有空控件,即使我在数组中有一些值
这就是我现在所拥有的
this.userVehicles= [];
this.userVehicles= [{Model: 'Fiat', RegistrationPlate: 'Taxi', LastServiceDate: 'Nov 11', Vin: '111', YearManufacture: '2015'}];
const vehicleFGs: any = this.userVehicles.map(vehicle => this._fb.group({
Model: [vehicle.model],
RegistrationPlate: [vehicle.registrationPlate],
LastServiceDate: [vehicle.lastServiceDate],
Vin: [vehicle.vin],
YearManufacture: [vehicle.yearManufacture],
}));
const vehicleFormArray: FormArray = this._fb.array(vehicleFGs);
((this.myAccountForm as FormGroup).get('Owner') as FormGroup).setControl('Vehicles', vehicleFormArray);
我认为我遇到的问题是在这一行
((this.myAccountForm as FormGroup).get('Owner') as FormGroup).setControl('Vehicles', vehicleFormArray);
我认为我没有正确绑定控件,有什么想法吗?
【问题讨论】:
-
你可以看看:stackoverflow.com/questions/50520278/…
.setControl() -
你能写一个答案吗?
-
让我看看我能做什么
-
您应该可以使用
.addControl()而不是.setControl()
标签: angular angular-reactive-forms