Implementing the Cart View
Once the user clicks the Add to Cart button, the item is added to the cart, and the view changes to the cart view. The cart view, shown in Listing 28.15, provides a list of products that currently exist in the cart, a price total, and buttons to check out or go back to shopping.
The following code implements a delete link in the cart to remove an item. It calls the function deleteFromCart()
, located in the controller, and passes product._id
to identify which item to delete:
<span class="delete" ng-click="deleteFromCart(product._id)">Remove</span>
Also, a quantity field links directly to the item.quantity
element, where an item comes from the ng-repeat
of the customer.shopping
cart ...
Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.