Making the Guide Interactive
Introduction: Making the Guide Interactive
Welcome back! In the last lesson, you built a step-by-step cooking guide page using a TypeScript component and its template. You set up the structure, added navigation buttons, and connected styles and logic within the component. That was a great start, but the page is still static — it doesn’t respond to user actions yet.
In this lesson, you will learn how to use TypeScript to make the guide page interactive within your component. By the end, your users will be able to move through recipe steps, hear instructions read aloud, use timers, and see updates instantly — all without reloading the page. This will make your cooking helper much more user-friendly and fun to use.
Quick Recap: The Static Guide Page
Let’s quickly remind ourselves what you built in the previous lesson. You created a Angular component with a template that shows the recipe name, the current step, and navigation buttons like Previous and Next. The template might look like this:
At this point, your component class defines the properties, but the logic for interactivity is not yet implemented.
Fetching and Showing Recipe Data
The first thing we want to do is load the recipe name and steps from the server and display them on the page. In a Angular component, you typically fetch data in the class and bind it to the template using properties.
Here’s how you can do it:
Explanation:
- The constructor loads the steps when the component is initialized.
- The
loadStepsmethod fetches the steps from the server using an injectedApiService. - The template binds to
recipeNameandcurrentStepTextto display the data. - If there’s an error, the
errorproperty can be used to show a message in the template.
Output:
When the component loads, you should see the recipe name and the first step appear.
