我有这个ts代码
item: Products[] = [];
this.myForm = this.fb.group({
'Quantity': new FormControl('', Validators.required),
'Price': new FormControl('', Validators.required),
'Total': new FormControl('', Validators.required)
});
我的功能提交
onAdd(){
console.log(this)
}
Html代码:
<form [formGroup]="myForm" (ngSubmit)="onAdd()" >
<div class="input-field col s12">
<input formControlName="Quantity" id="Quantity " type="number">
</div>
<div class="input-field col s12">
<input formControlName="Price" id="Price" type="number">
</div>
<div class="input-field col s12">
<div style="text-align:left;">
Subtotal:
<input formControlName="Total" id="Subtotal" type="number">
</div>
</div>
答案 0 :(得分:0)
总计需要将[(ngModel)]添加到输入中并创建一个添加逻辑的函数。 并在您的小计值中调用该函数,如
<form [formGroup]="myForm" (ngSubmit)="onAdd()" >
<div class="input-field col s12">
<input formControlName="Quantity" id="Quantity " type="number">
</div>
<div class="input-field col s12">
<input formControlName="Price" id="Price" type="number">
</div>
<div class="input-field col s12">
<div style="text-align:left;">
Subtotal:
<input formControlName="Total" type="text" value='{{ getSum() }}' [(ngModel)]="finalvalue"/>
</div>
</div>
您始终可以使用绑定属性{{}}
绑定该函数你需要将这个[(ngModel)] =“finalvalue”发送到你的onAdd()函数