我不能把两个数字的和加到下一个输入的金额上



这里的值1有一个10000的金额,然后我在值2中得到的结果是8500,在值3中我将输入一个所需的金额,并将其添加到值2中。例如:1000+8500。所以发生在我身上的是,我不能加Value3+Value2=Value4。我希望有人能帮助我。

https://stackblitz.com/edit/sum-ef7c94?file=src%2Fapp%2Fapp.component.ts,src%2App%2App.component.html

.html

<input style="width:300px" type="number"  (keypress)="numberOnlyWithDecimal($event,xyz)" 
[readonly]="true" [(ngModel)]="value1">
<input style="width:300px" type="number"  (keypress)="numberOnlyWithDecimal($event,xyz)" 
[readonly]="true" [(ngModel)]="value2" value = "{{myMath.abs(value1 * 0.15 - value1)}}">
<input style="width:300px" type="number"  (keypress)="numberOnlyWithDecimal($event,xyz)" 
[readonly]="true" [(ngModel)]="value3" >
<input style="width:300px" type="number"  (keypress)="numberOnlyWithDecimal($event,xyz)" 
[readonly]="true" [(ngModel)]="value4" value = "{{myMath.abs(value3 + value2)}}">

import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
value1: number = 10000;
value2: number = Math.abs(this.value1 * 0.15 - this.value1);
value3: number = 0;
value4: number = Math.abs(this.value2 + this.value3);
public myMath = Math;
ngOnInit() {}
}
<div class="container">
<div class="form-group">
<input
type="number"
class="form-control"
placeholder="FirstNumber"
[(ngModel)]="value1"
/><br />
Total<input
value="{{ myMath.abs(value1 * 0.15 - value1) }}"
type="number"
class="form-control"
placeholder="Total"
[(ngModel)]="value2"
/><br />
<input
type="number"
class="form-control"
placeholder="Input an Amount"
[(ngModel)]="value3"
/>
<input
type="number"
class="form-control"
placeholder=""
[(ngModel)]="value4"
value="{{ myMath.abs(value2 + value3) }}"
/>
</div>
</div>
Now you know how to add the 8500 to the Input amount ex: 1000 + 8500

或者检查这个片段:

https://stackblitz.com/edit/sum-sqe2kv?file=src%2Fapp%2Fapp.component.ts,src%2App%2App.component.html,src+2App%2App.component.css

相关内容

最新更新