Checking Out

You call the checkout() function, shown in Listing 28.25, when the user clicks the Checkout button in the cart view. This illustrates how useful AngularJS data binding really is: Because the customer information is always kept up-to-date, all that is necessary is to send an $http POST request with the parameter {updatedCart:$scope.customer.cart} to update the cart.

The cart is updated to ensure that any quantity changes made in the cart page are also persistent later on, if the user backs out of the purchase. If the request is successful, the view switches to shipping.html otherwise it stays on the checkout page.

Listing 28.25 cart_app.js-checkout: Implementing the checkout function in the controller


084     $scope.checkout = function(){
085       $http.post('/customers/update/cart',
086                  { updatedCart: $scope.customer.cart })
087        .success(function(data, status, headers, config) {
088          $scope.content = '/static/shipping.html';
089        })
090        .error(function(data, status, headers, config) {
091          $window.alert(data);
092        });
093     };


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset