I am currently working on implementing the Angular Material table into my project. I am encountering an issue when trying to define the [dataSource]="data"
, even though I am using code similar to the examples provided.
My question may seem basic, but my table data is just a simple array of objects. How can I successfully integrate this?
For illustration purposes, let's consider that my data is structured like this:
public data = [{ ID: 1, Code: "Hi" }, { ID: 2, Code: "Bye" }];
Below is the current code I am using:
<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>