This function returns the wrong grand total. When I add items to the cart, it returns a much higher grand total than is actually there. How can I fix it?
You can see the app in action at cart-64d3f.firebaseapp.com
In the component:
- totals = [];
- get grandTotal() {
- let i;
- let sub_total = 0;
- let grand_total = 0;
- if (this.isSubmitted == true) {
- if (typeof this.product_price !== "undefined" && typeof this.quantity !== "undefined") {
- sub_total = this.product_price * this.quantity;
- this.totals.push(sub_total);
- }
- }
- for (i = 0; i < this.totals.length; i++) {
- grand_total += this.totals[i];
- }
- return grand_total;
- }
In the HTML:
- <td>{{grandTotal | currency:'USD':true }}td>

Guest UserRank #816 · 2.8K reputationPosted Aug 13, 2020, 4:49 AM EDT
Varun SetiaRank #308 · 8.2K reputationPosted Aug 13, 2020, 5:59 AM EDT
Maureen MooreRank #5,080 · 312 reputationPosted Aug 13, 2020, 2:27 PM EDT
Maureen MooreRank #5,080 · 312 reputationPosted Aug 13, 2020, 2:44 PM EDT
Maureen MooreRank #5,080 · 312 reputationPosted Aug 14, 2020, 9:49 AM EDT
Maureen MooreRank #5,080 · 312 reputationPosted Aug 15, 2020, 2:42 AM EDT
Laxmidhar SahooRank #383 · 6.6K reputationPosted Aug 15, 2020, 11:45 PM EDT
Maureen MooreRank #5,080 · 312 reputationPosted Aug 16, 2020, 3:14 AM EDT
Maureen MooreRank #5,080 · 312 reputationPosted Aug 19, 2020, 2:04 AM EDT