title: Angular 2: Calculate sum of an element in ngFor
body: <p>I am trying to calculate the total (sum of amounts) outside the ngFor.</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code> &lt;div *ngFor="let item of items"&gt;
      &lt;input type="text" [(ngModel)]="item.price"&gt;  
      &lt;input type="text" [(ngModel)]="item.quantity" (ngModelChange)="item.amount=item.quantity*item.price"&gt;
      &lt;input type="text" [(ngModel)]="item.amount"&gt;    
  &lt;/div&gt;
  &lt;input type="text" [(ngModel)]="totalAmount"&gt;
  </code></pre>
  
  <p><strong>Scripe</strong></p>
  
  <pre><code>getTotal() {
      let total = 0;
      for (var i = 0; i &lt; this.items.length; i++) {
          if (this.items[i].amount) {
              total += this.items[i].amount;
              this.totalamount = total;
          }
      }
      return total;
  }
  </code></pre>
  
  <p>When I call the <strong>getTotal()</strong> function it returns total. But,how can I call that in textbox? or any other methods. </p>
  
  <p>Can any one help me how to solve this.</p>