If we have a list such as the one shown below:
elements = [
{ id: 1,
name: "one"
},
{ id: 3,
name: "three"
},
{ id: 5,
name: "five"
},
{ id: 6,
name: "six"
},
];
lists = [
{ id: 5,
name: "five"
},
{
id: 9,
name: "nine"
},
];
I am trying to make sure that only items with matching ids from 'elements' and 'lists' are displayed when using ngFor and ngIf directives. However, I am unsure of the correct syntax to achieve this.
<div *ngFor="let element of elements">
<p *ngIf = "lists.some(list => list.id === element.id)">
{{ element.name }}
</p>
</div>