I want to calculate and show the totalAmount when Amount
and Quantity
is entered.
I tried with (keyup) as well without success.
Here’s HTML
<div class="col-auto">
<label for="charges" class="form-label">Amount<span>*</span></label>
<input type="number" [(ngModel)]="expense.amount">
</div>
<div class="col-auto">
<label for="quantity" class="form-label">Qty</label>
<input type="number" (ngModelChange)="calcQuantity()" [(ngModel)]="expense.quantity">
</div>
<div class="col-auto">
<label for="totalAmount" class="form-label">Total<span>*</span></label>
<input type="number" [(ngModel)]="expense.totalAmount">
</div>
Here’s my TS file:
calcQuantity() {
this.expense.quantity = 1;
this.expense.totalAmount = this.expense.quantity>1?(this.expense.amount||0)*(this.expense.quantity||0):this.expense.amount;
}