Q:

Calculating within ngFor Angular 2

I have a list of results from year to year.
<tr *ngFor="let d of histroricalData; let i = index">
  <td>
    {{d.YearCalculation}}
  </td>
  <td>
    {{d.OverallResult}}%
  </td>
  <td>
    <!--subtract previous year from current -->
  </td>
</tr>

How would I subtract the previus result from the current one in the loop?
This is what I want to achieve using a regular for loop
 for (let i = 0; i < this.histroricalData.length; i++) {
      if (this.histroricalData[i - 1] != null) {
        let calc = this.histroricalData[i].OverallResult - this.histroricalData[i - 1].OverallResult
        console.log(Math.round(calc * 100) / 100);
      }
    }

A:

You can always take help of index,
So, you can use
 {{histroricalData[i - 1].OverallResult - histroricalData[i].OverallResult}}%

or,
 {{(histroricalData[i - 1]['OverallResult']) - (histroricalData[i]['OverallResult'])}}%

The code becomes,
<tr *ngFor="let d of histroricalData; let i = index">
  <td>
    {{d.YearCalculation}}
  </td>
  <td>
    {{histroricalData[i - 1].OverallResult - histroricalData[i].OverallResult}}%
  </td>
  <td>
    <!--subtract previous year from current -->
  </td>
</tr>

