Welcome back! So far, you connected the Angular frontend with the backend. In this lesson, we will focus on creating the template for the landing page of our Cooking Helper app. The landing page is the first thing users see when they visit your site. It should be clear, inviting, and easy to use.
By the end of this lesson, you will know how to build a well-structured Angular component template for the landing page. This will set the foundation for adding more features and interactivity in later lessons. Let’s get started!
Before we dive in, let’s quickly remind ourselves of a few important concepts:
- HTML Structure:
HTMLis the language used to create web pages. It uses tags like<html>,<head>, and<body>to organize content. - Angular Components: In
Angular, the UI is built using components. Each component has its own HTML template, TypeScript class, and optional CSS for styling. - Component Templates:
Angulartemplates use regular HTML but also support special syntax for data binding, event handling, and conditionally displaying content. - Routing:
Angularuses a router to map URLs to components. For example, the home page is usually mapped to aHomeComponent. - Data Binding:
Angularlets you bind data from your component class to the template using curly braces ({{ }}) and bind events using parentheses (e.g.,(click)).
If any of these ideas are new to you, don’t worry! We’ll see them in action as we build the landing page.
Let’s look at what our landing page needs. We want users to be able to:
- Search for recipes by entering ingredients.
- See the results of their search.
- View a list of popular recipes.
- Get a random recipe if they’re feeling adventurous.
To make this possible, our landing page will have four main sections:
- Search Section: A form where users can type in ingredients.
- Search Results Section: A place to show recipes that match the search.
- Popular Recipes Section: A list of recipes that are popular right now.
- Random Recipe Section: A button to get a random recipe and a spot to display it.
We will use this file structure
By organizing the page this way, we make it easy for users to find what they need and explore new ideas.
Let’s build the landing page step by step. We’ll use Angular’s component system and break the code into small, easy-to-understand pieces.
Let’s add the search form using Angular’s template syntax and form controls.
- The form uses
Angular’sFormControlfor managing input. - The
(ngSubmit)event calls theonSearch()method in the component. - The button is disabled while searching.
- If there is a value in the variable
searchError, we display it.
We use Angular’s structural directives to show or hide the results and to display the list of recipes.
@ifand@forareAngular’s template syntax for conditionals and loops.- The results are only shown after a search.
We use Angular’s data binding and directives to load and display popular recipes.
- The list updates automatically as data is loaded.
We use Angular’s event binding and data binding for interactivity and data display.
- The button triggers a method in the component to fetch a random recipe.
- The result is displayed using data binding.
Here’s the basic structure of the component class that supports the template:
- The component manages the state for the search, popular recipes, and random recipe sections.
- Methods like
onSearch()andfetchRandomRecipe()will be implemented in later units to handle user actions.
In this lesson, you learned how to build the landing page for the Cooking Helper app using Angular components and templates. We broke the page into clear sections: a search form, search results, popular recipes, and a random recipe feature.
Now that you have a solid landing page structure, you’re ready to practice these concepts in the upcoming exercises. You’ll get hands-on experience creating and editing Angular components, and soon you’ll see how to connect your app to real data and add even more interactivity. Great job getting started!
