I am attempting to calculate the sum of a value in an array obtained from an HTTP GET method and a subscribe function. I want to display the result in the HTML but it is not working.
I really hope someone can assist me with this because I am stuck.
Here is my TypeScript file:
result: any;
getSumFacture() {
let total: number;
this.http.get(this.url).subscribe((data: any) => {
this.products = data;
total = this.products.reduce((sum: any, current: { totalPrice: any; }) => sum + current.totalPrice, 0);
console.log(total);
return total;
});
}
And here is my HTML file:
{{result}}