I am trying to calculate the total (sum of amounts) outside the ngFor.
HTML
<div *ngFor="let item of items">
<input type="text" [(ngModel)]="item.price">
<input type="text" [(ngModel)]="item.quantity" (ngModelChange)="item.amount=item.quantity*item.price">
<input type="text" [(ngModel)]="item.amount">
</div>
<input type="text" [(ngModel)]="totalAmount">
Scripe
getTotal() {
let total = 0;
for (var i = 0; i < this.items.length; i++) {
if (this.items[i].amount) {
total += this.items[i].amount;
this.totalamount = total;
}
}
return total;
}
When I call the getTotal() function it returns total. But,how can I call that in textbox? or any other methods.
Can any one help me how to solve this.
items) instead and bind to the result.