matColumnDef=""
财产。参见下面的示例,
<!-- Position Column -->
<ng-container matColumnDef="position"> //matColumnDef PROPERTY IS "position" HERE.
<th mat-header-cell *matHeaderCellDef> No. </th>
<td mat-cell *matCellDef="let element"> {{element.position}} </td> //AND "position" IS ALSO USED HERE.
</ng-container>
因此,您的代码需要如下所示:
<main>
<div id="content">
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
</mat-form-field>
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!-- Position Column -->
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef> No. </th>
<td mat-cell *matCellDef="let element"> {{element.id}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="plate">
...
</ng-container>
<!-- Weight Column -->
<ng-container matColumnDef="status">
...
</ng-container>
<!-- Symbol Column -->
<ng-container matColumnDef="type">
...
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>
</main>