TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maureen Moore
NA
206
0
Getter not returning the right values
Jul 25 2020 9:38 AM
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
>
Reply
Answers (
3
)
Reusable Modal dialogue
How to select and save image file to local drive in Cloud application.