I'm learning Angular and its Angular Material UI Framework. After installing dependencies, I generated an Material Rank Table with this command:
ng generate @angular/material:table rank-table --module=app
I manually edited it to add a new column named extra
to the data displayed in the date. The generated code is this way:
<!-- Id Column -->
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Id</th>
<td mat-cell *matCellDef="let row">{{row.id}}</td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Name</th>
<td mat-cell *matCellDef="let row">{{row.name}}</td>
</ng-container>
<!-- extra Column -->
<ng-container matColumnDef="extra">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Extra</th>
<td mat-cell *matCellDef="let row">{{row.extra}}</td>
</ng-container>
This code duplication annoys me, since the class rank-table.component.ts
has an attribute defined as displayedColumns = ['id', 'name', 'extra'];
.
How could I put this code inside a loop on displayedColumns
? If it isn't possible, I'll accept the answer that explains to me why.