Reputation: 305
I would like to create a list of item. Each item will have a collection of elements within a div as labeled with "div for item 1" below. The number of items are not fixed thus the divs will required to be created dynamically. How do I accomplish that? Do I need to create each element one by one? Is there a better and faster approach?
In component.html
<div>
<div> //div for item 1
<div style="background-image: url(urlx)">
<span>{{text1}}</span>
</div>
<div>
<p>{{text2}}</p>
</div>
<a href="" title="DISCOVER">DISCOVER</a>
</div>
//div for item 2
//div for item 3
//....
</div>
Upvotes: 1
Views: 1275
Reputation: 271
You can use *ngFor statement. for example.
<div *ngFor="let list of lists">
<div>
<div style="background-image: url(urlx)">
<span>{{list.text1}}</span>
...
</div>
</div>
</div>
also, you have to declare lists
in .ts file.
Upvotes: 1