I am using Angular8, here I have got an array of objects as individual roles, which contains a list of users in it. Now I need to show those roles in separate tables. So I need to call the same code for 7 times as there are 7 roles with headings. Instead of calling the same code for 7 times, can it be looped along with the Role name as a heading, and if there is no data for that particular role, how can that be hidden?
HTML:
<div class="mb-3" *ngIf="contactsList?.length !=0">
<h6>Personal Lines Marketing</h6>
<table class="table table-hover accordion-table" id="accordionContact">
<thead>
<tr>
<th scope="col" *ngFor="let field of contactListDetails" (click)="sortContactsList(field.param)">
{{field.displayName}}
<i class="{{field.icon}}" aria-hidden="true"></i>
</th>
<th scope="col" class="width125"></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let contact of contactsList.plMarketing | paginate: config ;let i = index">
<td *ngFor="let field of contactListDetails" class="{{field.class}}" (click)="editContact(contact,contact.contactId)">
{{contact[field.param]}}
</td>
<td class="width125 {{paginationDisable?'link-disabled':''}}" ><button class="btn btn-outline-primary btn-table" title="Send Mail"
(click)="userDisplay(contact)" [disabled]="isReadOnly && mode ==1"><i class="far fa-envelope"></i></button>
</td>
</tr>
</tbody>
</table>
</div>
TS:
contactsList = [{
"version": null,
"statusCode": 200,
"message": "Success",
"isError": false,
"result": {
"plMarketing": [
{
"userId": 2,
"agentCode": 3343,
"userName": "New,New",
"phoneNumber": "123",
"faxNumber": "123",
"email": "[email protected]"
}
],
"clMarketing": [
{
"userId": 2,
"agentCode": 3343,
"userName": "New,New",
"phoneNumber": "123",
"faxNumber": "123",
"email": "[email protected]"
}
],
"plUnderWrite": [
{
"userId": 15,
"agentCode": 3343,
"userName": "ghghgh,hghgh",
"phoneNumber": null,
"faxNumber": null,
"email": "[email protected]"
}
],
"clUnderWrite": [
{
"userId": 19,
"agentCode": 3343,
"userName": "hghg,fse",
"phoneNumber": null,
"faxNumber": null,
"email": "[email protected]"
}
],
"plCorrespond": [
{
"userId": 18,
"agentCode": 3343,
"userName": "hghg,fse",
"phoneNumber": null,
"faxNumber": null,
"email": "[email protected]"
}
],
"clCorrespond": [
{
"userId": 15,
"agentCode": 3343,
"userName": "ghghgh,hghgh",
"phoneNumber": null,
"faxNumber": null,
"email": "[email protected]"
}
],
"accounting": [
{
"userId": 18,
"agentCode": 3343,
"userName": "hghg,fse",
"phoneNumber": null,
"faxNumber": null,
"email": "[email protected]"
}
],
"management": [
{
"userId": 16,
"agentCode": 3343,
"userName": "hghg,fse",
"phoneNumber": null,
"faxNumber": null,
"email": "[email protected]"
}
]
}
}]
So here, plMarketing, clmarketing, plunderwriting are all different roles, and all roles contain the same param names.
Please help me to loop without adding extra 7 times the same code.
DEMO: DEMO