I have an array of items that must be shown based on different roles. I am looking for the first item in the array that meets the ngIf condition.
Below is my code snippet:
This is how my Array initially looks:
parentTabList = [
{
name: 'abc',
label: 'abc',
icon : 'question_answer',
role : ['vend_perm','vend_temp','vend_subs']
},
{
name: 'xyz',
label: 'xyz',
icon : 'question_answer',
role : ['vend_perm','vend_subs']
}
]
This is my Html:
<ng-container *ngFor="let form of parentTabList let i = index">
<li *ngIf="form.role.includes(userRole)">
<a (click)="methodName(form)" [ngClass]="{'first-anchor': i === 0}">
{{form.label}}
</a>
</li>
</ng-container>
UserRole is a string value retrieved upon user login.
I also need to apply a ngClass to the anchor tag if it happens to be the first one displayed. (I am new here, so feel free to ask for more clarification).