If you find any errors, typos or have general feedback, select the text and click CTRL+ALT+ENTER.


In this tutorial, you’ll learn how to extend your AngularJS Pizza app by adding a shopping cart and custom pizzas interface. Please complete first part of this tutorial via the link before going ahead.

We are going to extend the previously created application by adding Cart and My Pizza pages. The Cart contains a list of names and prices, and the Delete from Cart button, as well as fields for entering phone number and address. The main menu is complemented with Add to Cart buttons. My Pizza page is designed similarly to the main menu, and we will also add Add to Cart and Remove from the list of custom pizzas buttons.

In the Cart page, will be an Order button to send a list from cart to the Orders database collection, then shopping cart is cleared. There will also be a button to empty the shopping cart.

The pizza PizzaCreator will now ask for the name and description of your custom pizza. There will also be a button to clear the list of selected ingredients.

In navbar, a field for a quick search by pizza name will be added. The search will be available on pages Menu, My pizza and Cart , as they have a similar structure. 

Before you begin

Tutorial level: advanced.

This tutorial assumes you have already created The Pizza app.

Try it yourself


Creating from the backup

You can extend this app app by following step-by-step tutorial below or create it from the backup.

To create an app from the backup:

  1. Click Create new app.
  2. Type an app name.
  3. Click From backup and select the project backup file.
  4. Click Create.

You still have to extend the database manually as described in this section below. If you’ve already created the database, find the X-Appery-Database-Id:

And paste it to PizzaDelivery_settings > database_id:database_id1

Adding new pages

Let’s continue developing your app. The app already has index, Menu, Details and PizzaCreator pages. We’re going to create two more pages.

  • Inside the app builder, go to CREATE NEW > Page. Add Custom and Cart pages:
  • Go to Project > Routing and set the following routing:
  • Go to the index page and add two more Link components to Navs
  • For the third Link set properties Text = My pizza and ng-click with the following code:

  • For the fourth Link set properties Text = Cart and ng-click with the following code:


Now you can run Test to check navigation.

Extending database

To continue creating the app database, click DATABASE in the builder or go to https://appery.io/database.

Open the PizzaDelivery database. There are already created Menu, Ingredientsand CustomPizza collections. 

Instead of creating collections manually, you can download .zip archive and unzip it. There are exported Cart and Orders collections as .json files. Just click Import a collection, type its name and click Choose file to select the previously unzipped files.

Cart collection

  • Create a Cart collection.
  • Add a column pizzaId of String type for referring to existing pizza from Menu or CustomPizza collection.
  • We are going to implement pizza search in other collections by pizzaId. To make it faster, add a column named custom of Boolean type. It will show whether pizza is custom (if True):

Orders collection

  • Create an Orders collection.
  • Add phone and address columns of String type.
  • Add a column items of Array type. This is an array of pizzas containing a flag custom that shows whether pizza is custom (if True):

Importing database services

We’ve already imported some services from the PizzaDelivery database. 

Inside the app builder, go to CREATE NEW > Database Services. Check the following services:

  • Cart collection: create, delete, list
  • Orders collection: create
  • CustomPizza collection: delete, list, read

The added services appear under Services section:

Building Scope of index and Menu pages

We are going to prepare SCOPE of the index page for work with custom pizzas.

  • Go to SCOPE of the index page.
  • Open the method init() that will be automatically run when the app starts. Paste the following code in the very beginning of that function:
  • Before triggering the list services, variables that will keep their responses should be created. Create two variables customPizzas and list with type of Array:
  • Now, let’s invoke the menu_list and custom_pizza_list services with the help of snippets, and bind their responses to the variables via mapping. In the editor, click the arrow to filter snippets, select Invoke service, and click Insert snippet.
  • Then, delete the text “service_name” in the code and  click CTRL+SPACE to get the drop-down with all the available services and autocomplete the needed service: PizzaDelivery_CustomPizza_list_service:
  • Sample code will be added to the function. The first (upper) Mapping button is for Before send mapping, the second one is for Success mapping.
  • Click the lower Mapping and create the following by dragging the $ sign over the customPizzas variable to the right:
  • Click Save & Replace. This will store the response of customPizzas list service to the customPizzas variable.
  • Place the cursor below the code and invoke the PizzaDelivery_Menu_list_service the same way, then map its response to list variable. Your init() function should look like the following:

    For now, to change the mapping, you should remove the generated code and create the mapping from scratch by clicking Mapping again. Visual mapping editing will be implemented soon.

  • Now, customPizzas and list arrays are available from scope of any screen (this is how index screen works).
  • Go to the Menu page SCOPE and clear the method init().

Building a Custom page

The Custom page is designed to handle custom pizzas.

  • Go to the Custom page and add a Grid Layout similar to the Menu page.
  • Set 5 cells (select the GridRow and click + three times).
  • For the first cell, set the Columns properties: Xtra-Small = 6, Large = 4:
  • For the second cell, set the Columns property Xtra-Small = 2:
  • For the third and fourth cells, set the Columns properties Xtra-Small = 2 and Large = 1:
  • For the fifth cell, set the Columns property Xtra-Small = 4 and Hidden = True for Medium, Small, Xtra-Small:
  • Select the GridRow and add property ng-repeat = item in customPizzas:
  • 013-GridRow1_properties_
  • Drag a ListGroup to the first cell, set its property Linked = True so a pizza name looks clickable:
  • Select thw ListGroupItem, set property Text = {{item.name}} and add property ng-click= goToDetails(item._id) (similarly to Menu):
  • Drag a Text component to the second cell, set its property Text = {{item.price | currency }}:
  • Add a Button component to the third cell, set its Type = Success, clear the Text property. Set the white shopping cart icon:
  • Add a Button component to the fourth cell, set its Type = Danger, empty Text property. Add property ng-click = removePizza(item). Set a white trash bin icon:
  • Add a Text component to the last cell, add property ng-bind = item.consist (similarly to Menu):
  • Go to the page SCOPE and add a function removePizza(item) with the following code: 
    The code above triggers the CustomPizza delete service, but without the mapping and code snippets as described here. You can choose which option you like more.
  • Now you can run Test to make sure Custom page is filled with custom pizzas from the database. If you still haven’t created any pizzas, add them in PizzaCreator and refresh the page.

Building a PizzaCreator page

The PizzaCreator page allows users to create a custom pizza recipe and submit it to an administrator review. We need to change it so a new pizza is also added to customPizzas array:

  • Go to the PizzaCreator page
  • Drag a Form component to the page and place it above the Save button.
  • Drag an Input and a Textarea components to Form groups.
  • Set the Input properties Placeholder = Pizza's name, ng-model = customPizza.name:
  • Set the Textarea property placeholder = Descriptionng-modelcustomPizza.about:
  • Drag a Text component above the Input and set TextHow would you like to call your pizza?:
  • Drag a Text component above the Textarea and set Text = Describe your pizza:
  • Select the Save button and add property ng-disabled = !customPizza.name so that it is disabled until you enter a pizza name:
  • Drag a Button component and place it after the Save button, and set its properties Text = Clear list and ng-click = clearList():
  • Go to SCOPE, open the method init() and add the following code in the beginning of it:

  • Replace the code of savePizza() with the following code (here, we delete the Modal code, add custom pizza to both database and customPizzas array, and clear the list and name after saving pizza):
  • Add a function clearList() with the following code:
  • Now, you can run Test to make sure the added pizza appears on MyPizza page. If you click a custom pizza name, its description won’t be displayed as the Details page looks for pizzas only in the Menu list. We need to pass the second argument custom via Routing what means the pizza is in the custom list.
  • On the Custom page, select the item with pizza name and add the second function parameter to ng-click = goToDetails(item._id, true):
  • Go to the SCOPE of the Menu page. Add the second argument custom to the method goToDetails(),and replace its code with the following:
  • Go to Routing and, for Detailsset the following path: /Details.html/:id/:custom 
  • Go to the SCOPE of the Details page and replace the code of method init() with the following code:
  • Now, you can run a test to make sure a description is opened on custom pizza name click.

Adding shopping cart

Adding addToCart buttons

  • Go to the Menu page and select GridRow.
  • Add one more cell and drag Text from the third cell to the new one.
  • For the new cell, set properties similar to the third cell (Xtra-Small = 2, Large = 4 and Hidden = True for Medium, Small, Xtra-Small):
  • For the third cell, remove all properties Hidden = True and remove Large = 4:
  • Drag a Button to it and set its Type = Success, empty the Text and set a shopping cart icon (similarly to Custom page), set property ng-click = addToCart(item):
  • Go to the Custom page, select a green shopping cart button, set property ng-click = addToCart(item, true). The last parameter means the pizza is custom:
    031-Button_properties - Copy17
  • Go to SCOPE of the index page. Add a function addToCart(item, custom) so that this method is available from any page. The method will take an item which is a pizza object, and read its id. Flag custom shows whether the pizza is custom, and its value will be saved to database Cart collection. Cart array will store a list of all the pizzas in the cart which we’ll add later. Paste the following code:

Building design of Cart page

  • Go to the Cart page. Drag a Grid Layout to the page and add 3 cells.
  • For the first cell, set properties Xtra-Small = 8, Large = 4:
  • For other cells, set Xtra-Small = 2:
  • For GridRow, set ng-repeat = item in cart:
  • Drag a ListGroup to the first cell, set ListGroupItem property Text = {{item.name}}:
  • Drag a Text component to the second cell and set its property Text = {{item.price | currency}}:
  • Drag a Button component to the third cell, set Type = Danger, remove Text, set white recycle bin icon and set ng-click = removeFromCart(item):
  • Add a Text component under the Grid, set its Text = Total: {{totalPrice | currency}}:
  • Add a Form component and fill it out similarly to the PizzaCreator. Drag a Text component, then Input, then one more Text and Textarea:
  • Set the Input property ng-model = phoneNumber, placeholder = Phone number:
  • Set Textarea property ng-model = addressplaceholder = Address:
  • Add a Button in the end of the Form (or under it). Set its Text = Order, ng-click = sendOrder(). Add attribute ng-disabled= !phoneNumber || !address so that the Button is disabled if some field is not filled:
  • Add one more Button component and set its TextClear cart, ng-click clearCart():

Building Scope of Cart page

  • Go to SCOPE of the Cart page. The code of method init() adds cart array to the index SCOPE. An item with attributes pizzaId and custom will be saved to database. Pizza name and price will be also copied to the cart array:
  • Add method removeFromCart(item):
  • Add method clearCart() to remove items from cart:
  • Add method sendOrder() that generates items array, phone number and address, and saves them in Orders collection. It clears the cart after the success message is displayed:
  • Now you can run a test to check how your shopping cart works.

Adding filter for a quick search

  • Go to DESIGN of the index page
  • Select Navbar and add a Form component to the right (bottom on Xtra-Small screen) container. Remove the second FormGroup.
  • Drag an Input component to the remaining FormGroup, set its properties placeholder  = Quick search... and ng-model = search.name:
  • Go to SCOPE of the index page and add the following code in the beginning of the method init():
    This is an object for filtering pizzas by name.
  • Go to DESIGN of the Menu page.
  • Select the GridRow and set the property ng-repeat= item in list | filter: search:
  • Go to DESIGN of the Custom page and set GridRow property ng-repeat= item in customPizzas |filter: search:
  • Go to DESIGN of the Cart page and set GridRow property ng-repeat= item in cart | filter: search:
  • Now you can run a test to check how filtering works.

Testing the app

It’s time to test the app. Click TEST button and the Menu opens:

Let’s try to filter pizzas by name:

Navigate to the PizzaCreator to create your own pizza:

After your recipe is ready, click the Save button:

Let’s check the list of custom pizzas:

Now open your shopping cart:

Click the Order button to order your pizzas: