I am attempting to display only the matched columns in a table, but I am unsure of how to achieve this. If anyone has any ideas or solutions, please help me out.
app.component.ts:
columnsOnly = ['name', 'id', 'rank'];
items = [
{ name: 'jean', surname: 'kruger', id: 1, place: 'ckh', rank: null },
{ name: 'bobby2', surname: 'marais2', id: 2, place: 'ckh', rank: null },
{ name: 'jean3', surname: 'kruger3', id: 3, place: 'ckh', rank: null },
{ name: 'bobby4', surname: 'marais4', id: 4, place: 'ckh', rank: null },
{ name: 'jean5', surname: 'kruger5', id: 5, place: 'ckh', rank: null },
{ name: 'bobby6', surname: 'marais6', id: 6, place: 'ckh', rank: null }
];
app.component.html:
<table>
<thead>
<tr>
<th *ngFor="let head of items[0] | keys: index as i">
<span *ngIf="head == columnsOnly[i]">
{{head}} </span>
</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of items">
<td *ngFor="let list of item | keys">{{item[list]}}</td>
</tr>
</tbody>
</table>
Demo: https://stackblitz.com/edit/angular-71f59e?file=app%2Fapp.component.html