June 2014
Intermediate to advanced
696 pages
38h 52m
English
You call the deleteFromCart() function, shown in Listing 28.24, from the cart template when the user clicks the Remove button. It iterates through the items in customer.cart, and if it finds the item, it uses the array.slice(index,1) method to delete it from the array.
Once the item is removed from $scope.customer.cart, you call an $http POST to the /customers/update/cart route to update the cart. This way, the cart is persistent and will be there even if the user closes the browser or navigates away. On success, this switches to cart.html; on failure, an alert window appears.
Listing 28.24 cart_app.js-deleteFromCart: Adding the delete function to handle deleting items from the cart
Read now
Unlock full access