I am trying to dynamically update a sum of two fields in angular based on user input. At first it is linked to some data taken from the database. I managed to change the input and update the sum, but I somehow need to subtract what was before in the field in sum calculation. Now the sum adds also what was previously in the field and I don't want that behaviour.
.html file
<div class="d-flex justify-content-center">
<form>
<input class = "textbox" type="text" name="Name" [ngModel]="user._30_geplant (change)="updateSum($any($event.target).value)">
</form>
</div>
<div class="d-flex justify-content-center">
<form>
<input class = "textbox" type="text" name="Name" [ngModel]="user._30_buro (change)="updateSum($any($event.target).value)">
</form>
</div>
<div class="d-flex justify-content-center">
<p class = "delta" [ngModel]="delta30" ngDefaultControl>{{delta30}}</p>
</div>
In the .ts file
constructor() {
this.delta30 = this.user._30_geplant + this.user._30_buro;
}
updateSum(sum: number) {
this.delta30 = (+this.delta30) + (+sum);
}
What I have tried so far seemed not to work.