import {Component, input} from '@angular/core'; import {FormArray, FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms"; import {GetProductDto, GetSupplierDto} from "../../services/api"; import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid"; import {NzFormControlComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; import {NzFlexDirective} from "ng-zorro-antd/flex"; import {NzTableComponent} from "ng-zorro-antd/table"; import {NzInputNumberComponent} from "ng-zorro-antd/input-number"; import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select"; @Component({ selector: 'app-add-product-supplier-form', imports: [ NzRowDirective, NzFormControlComponent, NzFormLabelComponent, ReactiveFormsModule, NzFlexDirective, NzColDirective, NzTableComponent, NzInputNumberComponent, NzOptionComponent, NzSelectComponent ], templateUrl: './add-product-supplier-form.html', styleUrl: './add-product-supplier-form.css', }) export class AddProductSupplierForm { addProductForm: FormGroup = new FormGroup({ supplierId: new FormControl(null, Validators.required), lines: new FormArray([], Validators.required), }); suppliers = input.required(); products = input.required(); get lines(): FormArray { return this.addProductForm.get('lines') as FormArray; } addProductToForm() { this.lines.clear(); this.products().forEach(x => { this.lines.push( new FormGroup({ productId: new FormControl(x.id), name: new FormControl(x.name), price: new FormControl(0, [Validators.required, Validators.min(0)]) }) ); }); } }