If you’re trying to display the subtotal, this is slightly harder. I’m going to assume you don’t care about that and just want the sum and average to be complete at some point. The main point here is that the template and *ngFor
loop should not be involved here. Do the work in a subscription.
Get rid of the calculate
functions and the async pipe.
items: Item[] = [];
totalPrice: number;
avgPrice: number;
constructor(af: AngularFire) {
af.database.list('/Evendido').subscribe((items) => {
this.items = items;
this.totalPrice = 0;
items.forEach((item) => {
this.totalPrice += item.Adicionar.price;
this.totalPrice += item.Platito.price;
this.totalPrice += item.carnita.price;
});
this.avgPrice = this.totalPrice / items.length;
});
}
<ion-item-sliding *ngFor="let item of items">
Also, and I believe I’ve implored you about this before: please define business interfaces. I’m getting to the point where I’m considering simply ignoring any questions that include any
anywhere in the code.