The model class Bike should be imported from the bike.model.ts file using the below statement.
- import { Bike } from './bike.model';
Refer to the screenshot to get a clear picture.
Now, the bike data is stored in ‘bikeList’ array in the App component – Parent component
Our next action is to loop though this array element and pass each array element to the bike-list-box component – child component
To loop through the array element, we can use the ngFor statement.
Open the ‘app.component.html’ file and create a <div> with *ng For statement
- *ngFor="let bikeEl of bikeList"
Please refer to the screenshot below.
Here, the ‘bikeList’ is the array that we have created inside the app.component.ts file.
And, bikeEl is the local variable to store each array item.
Save all changes and check our application in browser.
We will see the screen as in the below screenshot.
As we can see, the loop worked 3 times (we have only 3 elements in array) as expected and the child component ‘bike-list-box’ was invoked 3 times.
Conclusion
In this article, we have created modelclass for bike entity and created an array of type Bike. Then, we created 3 Bike objects and inserted into the array.
Then, we accessed the array elements in template file and looped through the array elements.
Here, we are using the hard coded data in the array. We will change this to an Angular service soon.
In the next article, we will see how to transfer the array element to bike-list-box component from app component. (Parent to Child)
Then we will display the details of each array element in bike-list-box component.
Happy Learning!