Try call the get in a ngAfterviewInit this error is very complicated, with changeDetection onPush should resolved but sometimes it's not possible
El sáb., 25 de jul. de 2020 11:35 a. m., Maureen Moore <[email protected]> escribió: > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/angular/55064620-1287-4e67-b33c-8f9ef98e924ao%40googlegroups.com > <https://groups.google.com/d/msgid/angular/55064620-1287-4e67-b33c-8f9ef98e924ao%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/angular/CACXfMfbvx0VD-S-G_7DNLG8UNd9bfoGaAdzQXz7FseAEvmWquw%40mail.gmail.com.
