Perhaps something is wrong with your way inputting things, that’s what happens usually when you try to get the value of something but then actually end up getting it’s memory address or something
What I failed to show was that the grandTotal is part of a for loop. That’s why the grandTotal shows a wild sum. It’s constantly being iterated over. How do I get the quantity and product_price outside of a for loop?
I am looping through the ngFor directive so the quantity and price get summed up repeatedly. But when I take the function out of the for loop it doesn’t have any access to the price and quantity variables.
The problem is that the price and quantity are getting submitted twice. Once when the quantity is increased or decreased and then again when the Add to Cart button calls the onSubmit function.
I am getting quantity and price not just when I click onSubmit but also when I click on the quantity buttons. This is what my quantity buttons look like:
The quantity buttons are submitting the quantity every time I click on the plus or minus image. I checked it in console.log. How can I prevent the buttons from submitting?
When I add a disabled for invalid form function to the quantity buttons and then add required to the text input field, it disables the buttons when I click on them.