- Lab
- Core Tech

Guided: Building a Storefront in Angular
This hands-on lab is designed to help you practice your understanding of Angular concepts such as Routing, Binding, and Styling. A series of guided steps will give you a walkthrough on how to apply your knowledge of these fundamental Angular concepts into an actual application. By the end of the lab, you will have demonstrated your ability to build a functioning Angular application using these concepts.

Path Info
Table of Contents
-
Challenge
Introduction
In this Angular guided lab, you have been given a demo app called Globoticket. Launching this app will display a storefront containing multiple "bookable" events. Your task in this lab will be to implement an event details component that will display information for each of these events.
The guided steps in this lab will review topics such as using the Angular CLI to generate components, dependency injection, routing, styling, and data binding. Tasks can be validated by clicking on the checkboxes next to them. If you are stuck or would like to compare solutions, a
solution
directory has been provided for you as well.The app will not run until you have completed the Using the Angular CLI step. Afterwards, you can launch the app at anytime during the lab by doing the following;
- Click the Run button at the bottom right of the Terminal.
- Then view the web page by clicking this link to the Angular website: {{localhost:4200}}
- You can also view the webpage by clicking the Web Browser tab's Refresh button, once the app is running. It may take a moment for the page to load.
-
Challenge
Using the Angular CLI
First, you will need to generate a new component for your event details page. This can be trivially done through an Angular command known as
ng generate
. This command can generate multiple templates of Angular files, but in this lab you will be using it to generate a component with theng generate component
command. You can also use abbreviated commands such asng g c
instead of the aforementioned command. Afterwards, you will need to perform dependency injection with anEventService
that has already been created (and imported) as it provides important data and functionality for your component. Once yourEventService
dependency has been injected, you will need to use it to initialize two properties for yourEventDetailComponent
class using thegetEvents()
andcreateNewEvent()
methods provided by the service. You will need to use thethis
keyword for the instance of yourEventService
. -
Challenge
Adding Routing
So far you've used the Angular CLI to generate a new component and performed dependency injection with an
EventService
to provide data and functionality to yourevent-detail
component. Now you will need to add routing, which will navigate and send data to your component whenever an event is clicked from the home page.Within the
imports
section of theapp.module.ts
file, you will see two paths already defined in theRouterModule
. You will need to define another path for yourevent-detail
component. Remember that routing paths are matched first, so it would be a good idea to put your new path above the other two paths. Now you will need to add routing to the home page so that each event will navigate to your component when clicked. Within thehome
directory of yoursrc/app
should be ahome.component.html
file. In this file there are multiplea
tags with an unspecifiedhref
link. You will need to replace each of thesehref
s with the[routerLink]
directive. Lastly, you will need to add logic within yourEventDetailComponent
to handle the incoming id parameter and find the corresponding event from youreventList
. To do this, you will need to perform dependency injection again with the importedActivatedRoute
andRouter
. TheActivatedRoute
can be used to retrieve theid
parameter using itssnapshot.paramMap.get('id')
call. Thisid
should be used to find a matching event from youreventList
(for example, by using thefilter()
function). TheRouter
can be used to navigate back to the home page with thenavigate(['/'])
call if an invalid id is given. LikeEventService
, you will need to usethis
for all of these calls. -
Challenge
Understanding Styling
There are many ways to style html and css selectors in Angular. A popular method, and one that Angular bootstraps by default when you generate a component, is the usage of
templateUrl
andstyleUrl
s. These properties that are defined within your component specify paths to external resources containing the html templates and css stylings to be used by your component. This helps keep your code modular and clean.When you generated your
event-detail
component, the components html and css files are initially empty. Running themoveTemplates
script from before has given you a baseline template and stylings for your component which you will modify in this step and the next.If you launch the app and click any event, you should now be able to route to your
event-detail
component thanks to the routing from the previous step. Don't be surprised that the page is blank, as we still need to implement data binding. For now, you will need to add css stylings to your html template to align theback to home
button. -
Challenge
Binding Data
You're in the home stretch, now! If you have launched the app as mentioned in the last step, you will have noticed that your
event-detail
component displays a blank page beside aback to home
andplace order
button. Even though your component has logic that retrieves a specified event from the parameters sent to it, you have not bound the retrieved data to the html template.In this final step, you will perform both one-way (using interpolation) and two-way binding for retrieved data, which will then be displayed in your
event-detail
component.Navigate back to the
event-detail.component.html
file. Near the start you will notice a bunch of fairly self-explanatory comments starting withAdd imageUrl
and ending withShow event price
. All of these are in fact properties of theselectedEvent
retrieved in your component. If you want to see the properties in depth, you can check theevent/eventInfo.ts
file to see the interface forEventInfo
. Now there should only be two pieces of data left to bind as denoted by the comments. The first one will require two-way binding, which is done by using the[(ngModel)]
directive. By binding thenumTickets
property of yourselectedEvent
to theselect
element, changing the number of tickets in the dropdown menu will change the value of thenumTickets
property. Then you can use interpolation to display the total order price as the product ofnumTickets
with theprice
, which will dynamically change depending on the number of tickets selected. All done! Now by launching your app and clicking each event you should be redirected to yourevent-detail
component which should display all the necessary event information.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.