I want to display some number values from an array of objects, the object itself is containing an array containing some specific data.
i tried going through the values with an *ngFor but the numbers that i am getting are displayed as a concatenation between the different values while i want to sum them up, here's a brief explanation of what i am facing :
the class "Order" :
export class OrdreMission{
public idOrder:number;
// other attributes here
public concern:Concern [];
public costs:costs[];
constructor(){
this.mission = new Mission();
this.costs= [];
this.concern = [];
}
}
how i am looping through my array (ofc after getting the appropriate data from my backend provider)
<table>
<thead> <!-- my headers --> </thead>
<tbody>
<tr *ngFor="let x of listOrders">
<!-- other data displayed here -->
<td>
<span *ngFor="let k of l.costs">
{{k.typeCost.code=="0808" && k!=undefined && k.idOrder==l.costs.idOrder?k.value:return}}
</span>
</td>
<td>
<span #old value="0" *ngFor="let x of l.costs">{{x.typeCost.code!="0808" && x.typeCost.code!="0606" && x!=undefined && x.idOrder==l.costs.idOrder? sum(old.value,x.value):return}}</span>
</td>
<td>
<span #old2 value="0" *ngFor="let o of l.costs">{{o.typeCost.code!="0606" && o!=undefined && o.idOrder==l.costs.idOrder?sum(old2.value,o.value):return}}</span>
</td>
<td>
<span #old3 value="0" *ngFor="let m of l.costs">{{m.typeCost.code=="0606" && m!=undefined && m.idOrder==l.costs.idOrder?sum(old3.value,m.value):return}}
</span>
</td>
<!-- other unrelated data here-->
</tr>
</tbody>
</table>
sum() method in my component :
sum(old:any,a:any):number{
if(!Number(old)){
return Number(a+0);
}
else if (!Number(old) && !Number(a)){
return 0;
}
return Number(a)+Number(old);
}
the results that i am getting are concatenated such as this :
As you can see the result displayed in last column is a concatenation between the first and second columns values,
that same column should be including the sum of the two previous columns and other values, but it's just making a concatenation.

+a+oldorNumber(a)+parseInt(old)similarly for otherreturn Number(a)+0;*ngFor? Use some method in component - pass parameter to it from template if thats necessaryngFormultiple times, you can use that single time and write a condition