在 angular2 中获取具有 'for loop' 的 table 列的总和

Get SUM of a table column with 'for loop' in angular2

我正在尝试获取 'table' 列的总和 (getShotsTotal),'forEach' 在 Ionic1 中工作正常但在 Ionic2 中失败,任何帮助将不胜感激。我认为可能需要标准 'Loop',但作为新手,我不确定正确的方法和代码。

HTML:

<tr class="row header" *ngFor = "let par of Course; let i=index" >
<td class="col">{{i +1}}</td>
<td class="col1">{{par.Index}}</td>
<td class="col">{{par.Par}}</td>
<td class="col2">{{getPoints(par)}}</td>
<td class="col">{{getShots()}}</td>
<td class="col3" ><select [(ngModel)]="par.sel" 
(change)="onChangeScore(par.sel)"><option  *ngFor= "let s of items" >{{s}}
</option></select></td>
</tr>

<tr class="row" style="height:32px">
<td class="col">Total</td>
<td class="col"></td>
<td class="col"></td>
<td class="col"></td>
<td class="col">{{getTotalShots()}}</td>
<td class="col"></td>
</tr>

TS:

getShots(par) {
let val =  this.selectedHcp - par.Index;
if (val > 17.4) {
  return 2;
} else if (val >= -0.5) {
  return 1;
} else if (val < -0.5) {
  return 0;
}
};


getTotalShots = function () {
if (!this.Par) { return 0;
                 }
var total = 0;
angular.forEach(this.Par, function (item, index) {
total = total + (this.getShots(item) || 0);
});
return total;
}; 

如果要循环存储在this.Par中的数组,可以直接使用forEach

var total = 0;
this.Par.forEach((item, index) => {
    total += this.getShots(item) || 0
});