I am using Angular8 and have an ngFor to display an array of people.
This is the Array
private myArray: {}[] =
[
{
"name": "name1",
"description": "description goes here",
},
{
"serviceName": "name2",
"description": "description goes here",
}
]
This is the HTML
<div class="content" *ngFor="let details of myArray">
<h2>{{details.name}}</h2>
<div class="description">{{details.description}}</div>
<ul *ngIf="isName1">
<li>
<i class="fa fa-check-circle"></i>
<span>item1</span>
</li>
<li>
<i class="fa fa-check-circle"></i>
<span>item2</span>
</li>
</ul>
</div>
I have a foreach loop which loops through the array and changes isName1
to true if it is the first in the array.
this.myArray.forEach(s => {
if(name === 'name1') {
this.isName1 = true;
}
});
What I am trying to do is to get the ul
to only show for the first element but not the 2nd, yet it is coming up for both. Is there any way to achieve this?
Thanks