我有这个标记:
<div *ngFor="let quantity of model.quantities">
<div class="form-group kt-form__group row">
<label class="col-lg-2 col-form-label">Quantity:</label>
<div class="col-lg-6">
<mat-form-field class="example-full-width">
<input matInput [(ngModel)]="quantity.name" name="quantityname" placeholder="Enter Quantity" type="text">
</mat-form-field>
</div>
</div>
<div class="form-group kt-form__group row">
<label class="col-lg-2 col-form-label">Price:</label>
<div class="col-lg-6">
<mat-form-field class="example-full-width">
<input matInput [(ngModel)]="quantity.price" name="quantityprice" placeholder="Enter Price" type="text">
</mat-form-field>
</div>
</div>
<hr />
</div>
每次我在模型中添加一个数量类型的新对象时,为数组中的每个对象设置相同的值,最后输入的值https://screencast-o-matic.com/watch/cqQ1Fbt4zL
这是按钮单击事件:
addNewQuantity() {
if (this.newQuantity) {
let quantity = new PriceGridQuantity();
quantity.name = this.newQuantity;
this.model.quantities.push(quantity);
this.newQuantity = '';
}
}
更新:模型添加:
model: any = {
TenantId: '',
CustomFieldName: '',
quantities: []
};