I am currently developing a Fruit Shop web application with Angular, and I've encountered a peculiar issue that I've been struggling to resolve.
Here is an overview of the application's functionality:
On the main page, users can browse through a variety of fruits displayed as Bootstrap Cards. They have the option to add these fruits to their cart using "Add to Cart," "-" and "+" buttons. Once they are done selecting items, they can proceed to checkout and make payments.
The key components I have implemented include:
products
: The main component responsible for displaying all available products on the app's main page.productCard
: Represents each fruit card displayed on the products component using *ngFor directive.productQuantity
: Controls the logic for adding, subtracting, or deleting items from the user's cart. This component is intended for use in both the main page and the Cart page.
In addition to the components, I have defined various models to manage entities within the application:
- cart.ts: Contains properties and methods related to managing the user's cart, such as storing selected items and calculating quantities.
- cart-item.ts: Defines properties for individual items in the cart, including quantity and product details.
- product.ts: Represents the attributes of a product, such as name and price.
Below are snippets of code to provide clarity:
Products Component Class:
(Code snippet provided)
Products Component Markup:
(Code snippet provided)
ProductCard Component Class:
(Code snippet provided)
ProductCard Component Markup:
(Code snippet provided)
ProductQuantity Component Class:
(Code snippet provided)
ProductQuantity Component Markup:
(Code snippet provided)
Cart Service:
(Code snippet provided)
cart.ts (Cart model):
(Code snippet provided)
cart-item.ts (CartItem model):
(Code snippet provided)
product.ts (Product model):
(Code snippet provided)
Exception Encountered:
core.js:6185 ERROR TypeError: ctx.cart.getQuantity is not a function
at ProductCardComponent_Template (product-card.component.html:7)
at executeTemplate (core.js:11949)
at refreshView (core.js:11796)
at refreshComponent (core.js:13229)
at refreshChildComponents (core.js:11527)
at refreshView (core.js:11848)
at refreshDynamicEmbeddedViews (core.js:13154)
at refreshView (core.js:11819)
at refreshComponent (core.js:13229)
at refreshChildComponents (core.js:11527)