Javascript 要在角2的{{}中添加两个值吗
我有一张这样的表格Javascript 要在角2的{{}中添加两个值吗,javascript,angular,Javascript,Angular,我有一张这样的表格 <form> <div class="col-lg-3 col-md-3 col-sm-12"> <mat-form-field class="example-full-width"> <input type="text" matInput placeholder="Percent" formControlName="txtTaxLinePerc" (change)="changeTotal()"&g
<form>
<div class="col-lg-3 col-md-3 col-sm-12">
<mat-form-field class="example-full-width">
<input type="text" matInput placeholder="Percent" formControlName="txtTaxLinePerc" (change)="changeTotal()">
<span matSuffix>%</span>
</mat-form-field>
</div>
<div class="col-lg-3 col-md-3 col-sm-12">
<mat-form-field class="example-full-width">
<input type="text" matInput placeholder="Percent" formControlName="txtCompoundTaxPerc" (change)="changeTotal()">
<span matSuffix>%</span>
</mat-form-field>
</div>
<form>
<span>{{get added value}}</span>
我想显示txtTaxLinePerc和txtCompoundTaxPerc的附加值
我该怎么做呢
我已经尝试添加{{txtTaxLinePerc.value+txtCompoundTaxPerc.value}
,但它没有添加它,只是将这些值串联起来,就像这样20+40
它将给出2040
试试这个
{{txtTaxLinePerc + txtCompoundTaxPerc}}
对组件文件的更改
get txtTaxLinePerc() {
return this.addTaxTypeForm.controls.txtTaxLinePerc.value
}
get txtCompoundTaxPerc() {
return this.addTaxTypeForm.controls.txtCompoundTaxPerc.value
}
在组件类中
sum: any
在changetall()方法中
把这一笔金额固定在跨度内
<span>{{sum}}</span>
{{sum}
{{txtTaxLinePerc+txtCompoundTaxPerc}}
并更改您的.ts
文件
get txtTaxLinePerc() {
return this.addTaxTypeForm.controls.txtTaxLinePerc.value
}
get txtCompoundTaxPerc() {
return this.addTaxTypeForm.controls.txtCompoundTaxPerc.value
}
因为现在您返回一个,并且希望从中获取值,所以如果要使用ReactiveForms,您必须向表单中添加
formGroup
指令。然后您可以通过addTaxTypeForm.get('txtTaxLinePerc').value
获取输入值
所以你可以编辑你的gettes
get txtTaxLinePerc() {
return this.addTaxTypeForm.get('txtTaxLinePerc').value
}
get txtCompoundTaxPerc() {
return this.addTaxTypeForm.get('txtCompoundTaxPerc').value
}
在您的html中:
{{ txtTaxLinePerc + txtCompoundTaxPerc}}
你试过这个“{txtTaxLinePerc}{{txtCompoundTaxPerc}}
get txtTaxLinePerc() {
return this.addTaxTypeForm.get('txtTaxLinePerc').value
}
get txtCompoundTaxPerc() {
return this.addTaxTypeForm.get('txtCompoundTaxPerc').value
}
{{ txtTaxLinePerc + txtCompoundTaxPerc}}