To implement shoppingController
, you need to initialize the scope values that you need. The code in Listing 28.21 initializes the shopping scope. The $scope.months
and $scope.years
arrays populate the credit card form. $scope.content
determines which AngularJS partial is rendered in the view. It is initialized to products.html
so the user can begin shopping.
Next, there are three $http
requests that get the products, customer, and orders and use the results to set the $scope.products
, $scope.product
, $scope.customer
, and $scope.orders
objects that are utilized in the AngularJS views.
004 $scope.months = [1,2,3,4,5,6,7,8,9,10,11,12];
005 $scope.years = [2014,2015,2016,2017,2018,2019,2020];
006 $scope.content = '/static/products.html';
007 $http.get('/products/get')
008 .success(function(data, status, headers, config) {
009 $scope.products = data;
010 $scope.product = data[0];
011 })
012 .error(function(data, status, headers, config) {
013 $scope.products = [];
014 });
015 $http.get('/customers/get')
016 .success(function(data, status, headers, config) {
017 $scope.customer = data;
018 })
019 .error(function(data, status, headers, config) {
020 $scope.customer = [];
021 });
022 $http.get('/orders/get')
023 .success(function(data, status, headers, config) {
024 $scope.orders = data;
025 })
026 .error(function(data, status, headers, config) {
027 $scope.orders = [];
028 });