# Lesson 8: Use *ngFor to list objects in component This tutorial lesson demonstrates how to use `ngFor` directive in Angular templates in order to display dynamically repeated data in a template. **Estimated time**: ~10 minutes **Starting code:** **Completed code:** ## What you'll learn * You will have added a data set to the app * Your app will display a list of elements from the new data set using `ngFor` ## Conceptual preview of ngFor In Angular, `ngFor` is a specific type of [directive](guide/built-in-directives) used to dynamically repeat data in a template. In plain JavaScript you would use a for loop - ngFor provides similar functionality for Angular templates. You can utilize `ngFor` to iterate over arrays and even asynchronous values. In this lesson, you'll add a new array of data to iterate over. For a more in depth explanation, please refer to the [Built-in directives](guide/built-in-directives#ngFor) guide. ## Step 1 - Add housing data to the `HomeComponent` In the `HomeComponent` there is only a single housing location. In this step, you will add an array of `HousingLocation` entries. 1. In `src/app/home/home.component.ts`, remove the `housingLocation` property from the `HomeComponent` class. 1. Update the `HomeComponent` class to have a property called `housingLocationList`. Update your code to match the following code:
Do not remove the `@Component` decorator, you will update that code in an upcoming step.
## Step 2 - Update the `HomeComponent` template to use `ngFor` Now the app has a dataset that you can use to display the entries in the browser using the `ngFor` directive. 1. Update the `` tag in the template code to this: Note, in the code `[housingLocation] = "housingLocation"` the `housingLocation` value now refers to the variable used in the `ngFor` directive. Before this change, it referred to the property on the `HomeComponent` class. 1. Save all changes. 1. Refresh the browser and confirm that the app now renders a grid of housing locations. ## Lesson review In this lesson, you used the `ngFor` directive to repeat data dynamically in Angular templates. You also added a new array of data to be used in the Angular app. The application now dynamically renders a list of housing locations in the browser. The app is taking shape, great job. If you are having any trouble with this lesson, you can review the completed code for it in the . ## Next steps * [Lesson 9 - Add a service to the application](tutorial/first-app/first-app-lesson-09) ## For more information about the topics covered in this lesson, visit: * [Structural Directives](/guide/structural-directives) * [ngFor guide](/guide/built-in-directives#ngFor) * [ngFor](/api/common/NgFor) @reviewed 2023-07-11