Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 要在角2的{{}中添加两个值吗_Javascript_Angular - Fatal编程技术网

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}}