Using basic table, I could able to render dynamic rows and column
<tbody>
<tr *ngFor="let row of data">
<td *ngFor="let val of row">
{{ val }}
</td>
</tr>
</tbody>
</table>
So the same logic, when i tried it with angular mat-table I'm getting this error
ERROR Error: Duplicate column definition name provided: "undefined"
<mat-table #table [dataSource]="data">
<ng-container [matColumnDef]="col" *ngFor="let row of data">
<mat-header-cell *matHeaderCellDef> {{ row }} </mat-header-cell>
<mat-cell *matCellDef="let element"> {{ element[col] }} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="data"></mat-header-row>
<mat-row *matRowDef="let row; columns: data"></mat-row>
</mat-table>
Please help.
UPDATE
I wanted to display the excel data in mat-table.
I can display it using simple table.
Please look into the below stackblitz
[matColumnDef]="col"but how doescolchange? Therefore it's duplicate. Also.columns: datais another thing that looks wrong to me. It should be a string array of all the column names. See material.angular.io/components/table/overview