I´m having problem displaying data inside the table which has column and row headers. I´m trying to make it dynamic by using *ngFor. Can you suggest how to handle *ngFor in this case?
Ts file with data:
export class NewScreen {
rows = [
'Name',
'Surname',
'Subjects',
'Grade',
];
data = [
{
student: 'Student 1',
name: 'Alex',
surname: 'Smith',
subjects: ['Math','Geometry'],
grade: ['A','B'],
},
{
student: 'Student 2',
name: 'Michael',
surname: 'Laurent',
subjects: ['Math','Geometry'],
grade: ['B','C'],
},
{
student: 'Student 3',
name: 'Sophie',
surname: 'Miller',
subjects: ['Math','Geometry'],
grade: ['A','A'],
},
];
}
HTML:
I have been trying to find solution to put inside {{???}} which would result in displaying following table structure, but with no luck:
<table>
<thead>
<tr>
<th></th>
<th *ngFor="let column of data">{{ column.student }}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of rows">
<th>{{ row }}</th>
<td *ngFor="let value of data | keyvalue">{{ value.value[i + 1] }}</td>
</tr>
</tbody>
</table>
{{ item.value }}only, it is displayed like this: [object Object] for each field