I'm trying to make use of the Angular Material table. I'm trying to use the same code as the examples they have but I tin into a problem when I have to define the [dataSource]="data"
.
This question may sound stupid but my table data is a simple array of objects, how can I implement that?
for the sake of explaining let's say my data looks like this:
public data = [{ ID: 1, Code: "Hi" }, { ID: 2, Code: "Bye" }];
Here's the code I currently have:
<div class="example-container mat-elevation-z8">
<mat-table #table [dataSource]="data">
<ng-container matColumnDef="number">
<mat-header-cell *matHeaderCellDef> Number </mat-header-cell>
<mat-cell *matCellDef="let row"> {{ row.ID }} </mat-cell>
</ng-container>
<ng-container matColumnDef="Code">
<mat-header-cell *matHeaderCellDef> Code </mat-header-cell>
<mat-cell *matCellDef="let row">{{row.Code}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
</div>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…