Не уверен, правильно ли я вас понял.
Вот как можно использовать реактивные формы в вашем случае:
myForm: FormGroup;
constructor(private fb: FormBuilder) {}
ngOnInit(): void {
this.myForm = this.fb.group({
city: [null, Validators.required),
comboDescription: [null, Validators.required),
label: [null, Validators.required),
price: [null, [Validators.required, Validators.min(1)]),
productsIds: this.fb.array([], Validators.required),
qtyIds: this.fb.array([], Validators.required)
})
}
// create getters to retrieve the form array controls from the parent form group
public get productsIds(): FormArray {
return this.myForm.get('productsIds') as FormArray;
}
public get qtyIds(): FormArray {
return this.myForm.get('qtyIds') as FormArray;
}
// create methods for adding and removing productsIds
public addProduct(): void {
this.productsIds.push(this.fb.control('', [Validators.required]));
}
public removeProduct(index: number): void {
if(this.productsIds.length < 1) {
return;
}
this.productsIds.removeAt(index);
}
// do the same for the qtyIds
В шаблоне:
<form [formGroup]="myForm">
.
.
.
// example for productsIds
<div formArrayName="productsIds">
<button (click)="addProducts()">Add Product</button>
<div *ngFor="let productId of productsIds.controls; index as i">
<input type="text" [formControlName]="i">
<button (click)="removeProduct(i)">Remove Product</button>
</div>
</div>
.
.
.
</form>