我是 Angular 2/4 的新手,也是 Web 开发的新手。我有这个表格,它在购买表格中收集产品变体的信息。我已经构建了一个 formArray 的 formGroups 变体,如下面的 HTML 所示。
<form [formGroup]="this.purchaseInvoiceItemVariantsForm" novalidate>
<div formArrayName="variants">
<div *ngFor="let variant of this.purchaseInvoiceItemVariantsForm.controls.variants.controls; let i = index">
<div [formGroupName]="i">
<md-input-container>
<input mdInput placeholder="Product Code" formControlName="productBarcode" class="input--small" [readonly]="this.mode == 'view'">
</md-input-container>
<md-input-container>
<input mdInput placeholder="Color" formControlName="variant1" class="input--small" [readonly]="this.mode == 'view'" required>
</md-input-container>
<md-input-container>
<input mdInput placeholder="Size" formControlName="variant2" class="input--small" [readonly]="this.mode == 'view'" required>
</md-input-container>
<md-input-container>
<input mdInput placeholder="MRP" formControlName="mrp" class="input--small" [readonly]="this.mode == 'view'">
</md-input-container>
<md-input-container>
<input mdInput placeholder="Purchase Price" formControlName="purchasePrice" class="input--small" [readonly]="this.mode == 'view'"
required>
</md-input-container>
<md-input-container>
<input mdInput placeholder="Sell Price" formControlName="sellPrice" class="input--small" [readonly]="this.mode == 'view'"
required>
</md-input-container>
<md-input-container>
<input mdInput placeholder="Quantity" formControlName="variantQuantity" class="input--small" [readonly]="this.mode == 'view'" required>
</md-input-container>
<md-input-container>
<input mdInput placeholder="Discount" formControlName="variantDiscount" class="input--small" [readonly]="this.mode == 'view'">
</md-input-container>
<button md-icon-button (click)="removeVariant(i)" color="warn" *ngIf="purchaseInvoiceItemVariantsForm.controls.variants.length > 1 && this.mode != 'view'"><md-icon>delete</md-icon></button>
</div>
</div>
现在,一旦用户添加了 3 个变体,我希望能够听到 formControl“productBarcode”的 valueChanges,以便我可以从数据库中获取颜色和尺寸的详细信息。
有什么建议可以实现吗?
提前致谢!
问候, 纳文