Maureen Moore

Maureen Moore

  • NA
  • 206
  • 0

Trying to sum up the grandTotal doesn't work

Jul 17 2020 5:56 PM
I use the following function in my controller:
  1. sum = 0;  
  2. total_price = 0;  
  3.   
  4. get grandTotal() {  
  5. this.total_price = this.quantity * this.product_price;  
  6. this.sum += this.total_price;  
  7. return this.sum;  
  8. }  
I get quantity and product_price from the onSubmit function:
  1. onSubmit(quantity, product_price){  
  2. this.product_price = parseFloat(product_price);  
  3. const data = {  
  4. quantity,  
  5. product_price  
  6. };  
  7. this.items.push(data);  
  8. localStorage.setItem('items', JSON.stringify(this.items));  
  9. }  
I display grandTotal with the following:
  1. <div> {{ grandTotal | currency:'USD':true }} </div>  
I get wild values for grandTotal and I get the error: Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.

Answers (13)