Попробуйте этот простой метод ..
.ts
tableObj = [{
Name: "Ram",
Grade: "A",
RollNo: "10001",
Address: "ABC",
SrNo: 1
},{
Name: "Sam",
Grade: "B",
RollNo: "10002",
Address: "xyz",
SrNo: 2
}];
headers = [];
ngOnInit() {
this.tableObj.map((item) => {
this.headers = Object.keys(item);
})
}
getData(item) {
return Object.keys(item);
}
. html
<table border="1">
<tr>
<th *ngFor="let header of headers"> {{header}} </th>
</tr>
<tr *ngFor="let item of tableObj">
<td *ngFor="let data of getData(item)"> {{item[data]}} </td>
</tr>
</table>