Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.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
Angular 角度6,表格,按钮点击计算_Angular_Forms_Button - Fatal编程技术网

Angular 角度6,表格,按钮点击计算

Angular 角度6,表格,按钮点击计算,angular,forms,button,Angular,Forms,Button,我正在试验角度。。。我需要一些帮助 > 在本例中,我想读取输入值i04draw,执行一些运算,然后在html站点上显示到this.i03AvailFunds。但我不知道如何从输入屏幕获取值。 假设输入为I040 我只想从i04draw中减去10,然后将结果重新发布到i03AvailFunds this.i03AvailFunds=this.i02draw-10 > 输入字段I04Retrach是一个数字。我想在上面添加一些输入掩码,就像这样$0 因此,这是一个验证。 -数字键 -屏幕将自动执行类

我正在试验角度。。。我需要一些帮助

> 在本例中,我想读取输入值i04draw,执行一些运算,然后在html站点上显示到this.i03AvailFunds。但我不知道如何从输入屏幕获取值。 假设输入为I040

我只想从i04draw中减去10,然后将结果重新发布到i03AvailFunds

this.i03AvailFunds=this.i02draw-10

> 输入字段I04Retrach是一个数字。我想在上面添加一些输入掩码,就像这样$0 因此,这是一个验证。 -数字键 -屏幕将自动执行类似于$2000.00

值:{myForm.Value | json} 帐户ID:{sAccount}

I01信用额度:{{i01LOC}

i02Ballance:{{i02Ballance}}

I03可用资金:{{I03可用资金}

提交请求 对于>
您需要访问被动表单值,在您的案例中使用:

this.myForm.value
用于整个form.value或
this.myForm.controls.i04draw.value
recalc()函数中的


示例:单击mat按钮时,使用表单中的输入更改this.i03AvailFunds值:

recalc(){
    this.i03AvailFunds = (this.myForm.controls.i04WithDraw.value - 10) 
}


对于>
我来说,最好的办法是在输入中添加一个带美元符号的前置图标,否则您将不得不使用带$的字符串而不是数字。

尝试类似这样的操作
this.form.controls['i03AvailFunds'].setValue(this.i04draw)
 <mat-card class="example-card">
  <mat-card-header>
    <!-- <div mat-card-avatar class="example-header-image"></div> -->
    <!-- <mat-card-title>Extra Credit</mat-card-title>
    <mat-card-subtitle>The Example</mat-card-subtitle> -->
  </mat-card-header>
  <!-- <img mat-card-image src="https://material.angular.io/assets/img/examples/shiba2.jpg" alt="Photo of a Shiba Inu"> -->
  <mat-card-content>

    <form [formGroup]="myForm">
      <div>
        Value: {{ myForm.value | json }}
    </div>
      <p>Account ID :{{ sAccount }}</p>
      <p>i01Line Of Credit : {{ i01LOC }}</p>
      <p>i02Ballance : {{ i02Ballance }}</p>
      <p>i03Available Funds : {{ i03AvailFunds }}</p>
          <input formControlName="i04Withdraw">
      <button mat-raised-button (click)="recalc()" color="primary">SUBMIT REQUEST</button>
     </form>

   </mat-card-content>
  <mat-card-actions>
    <!-- <button mat-button>LIKE</button>
    <button mat-button>SHARE</button> -->
  </mat-card-actions>
</mat-card>
recalc(){
    this.i03AvailFunds = (this.myForm.controls.i04WithDraw.value - 10) 
}