My terminal is displaying 3 errors:
- Error TS2540: Unable to assign to 'i' because it is a constant or read-only property.
- Error TS2540: Unable to assign to 'result' because it is a constant or read-only property.
- Error TS2322: Type '0' cannot be assigned to type 'void'.
component.ts
total: any;
totalPrice(): void {
const result = 0;
for (
const i = 0; i < this.datas.length; i++
) { const data = this.datas[i];
result = result + data.total;
}
return result;
}
component.html
<td>{{ data.name }}</td>
<td>{{ data.price }}</td>
<td>{{ data.quantity }}</td>
<td>{{ data.total }}</td>
{{ totalPrice() }}
I am currently using *ngFor to iterate through a list, and the purpose of the function totalPrice() is to calculate the sum of all the data totals.