【发布时间】:2021-11-29 13:48:43
【问题描述】:
我在表格中有一个产品列表,每个项目都有一个值,当用户在文本框中输入数量时,我想获得价值并将其显示在下一列中。我尝试了以下方法,它将所有项目的值相乘。
Ts 代码
clientProductForm = new FormGroup({
productQty: new FormControl("", Validators.required)
});
proQty: number;
quantityChange(event) {
this.proQty = this.clientProductForm.get("productQty").value;
}
HTML 代码
<tr *ngFor="let products of clientProducts">
<td>{{ products.Name }}</td>
<td>{{ products.DistributorPrice}}</td>
<td><input type="number" class="form-control my-n1" formControlName="productQty" (keyup)="quantityChange($event)" /></td>
<td>{{ products.DistributorPrice * proQty}}</td>
<td>
<button class="btn btn-success">Add</button>
</td>
</tr>
【问题讨论】:
-
add按钮有什么用? -
@navnath 客户端填写数据后。我会用它来发帖
-
您只有一个 proQty - 但有多个产品..
-
@MikeOne 有没有办法实现我的目标或者你有 B 计划?
-
您可能希望扩展您的产品数组并为每个产品添加数量和小计键。
标签: angular typescript angular-reactive-forms