.html
<ng-container *ngFor="let contact of listContact | async; let index = index;">
<h6 class="title" *ngIf="contact && contact['type']">
{{contact['type']}}
</h6>
<div> {{contact['id']}}</div>
</ng-container>
listContact holds an observable with the following data:
[
{
"id": "u-8cf4161b-240f-5d7a-b5df-0522739c62d9",
"type": "Peoples"
},
{
"id": "u-0580ff64-c959-5690-bc54-16c43b28065d",
"type": "Peoples"
},
{
"id": "u-44e5a40a-a367-55e0-baf1-1eacccafe5f2",
"type": "Teams"
}
]
The desired HTML output should be:
Peoples
u-8cf4161b-240f-5d7a-b5df-0522739c62d9
u-0580ff64-c959-5690-bc54-16c43b28065d
Teams
u-44e5a40a-a367-55e0-baf1-1eacccafe5f2
To prevent repeating the same {{contact['type']}}
in the view if it's the same as the previous one during the loop, a check needs to be added. The title which depends on {{contact['type']}}
should also not repeat until the current one is different from the previous one.
How can this issue be handled in HTML?