I am trying to sum up all of my sub totals and return a grand total but I 
get wild values and I used to get the error: Expression has changed after 
it was checked. 

When I use 
import { ChangeDetectionStrategy } from '@angular/core';
@Component({
changeDetection: ChangeDetectionStrategy.OnPush
}) 


it suppresses the expression has changed error but I still get wild values 
for the grand total. 

This is in my component: 

totals : number[ ] = [ ];


get grandTotal() {


let i;
let sub_total = 0;
let grand_total = 0;
sub_total = this.product_price * this.quantity;


if (typeof this.product_price  === "undefined") {
return 0;
} else {
this.totals.push(sub_total);
for (i = 0; i < this.totals.length; i++) {
 grand_total += this.totals[i];
}
return grand_total;
}
}



This is in my HTML;

<div>Grand Total {{ grandTotal }}</div>


-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/angular/55064620-1287-4e67-b33c-8f9ef98e924ao%40googlegroups.com.

Reply via email to