使用角度材料:6.4.5 和角度材料:6.4.3 进行了测试 但面对这个问题
我已经实现了https://material.angular.io/components/table/overview
上提供的完全相同的示例.html
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8" *ngIf="displayedColumns">
<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef> No. </th>
<td mat-cell *matCellDef="let element"> {{element.position}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>
<!-- Weight Column -->
<ng-container matColumnDef="weight">
<th mat-header-cell *matHeaderCellDef> Weight </th>
<td mat-cell *matCellDef="let element"> {{element.weight}} </td>
</ng-container>
<!-- Symbol Column -->
<ng-container matColumnDef="symbol">
<th mat-header-cell *matHeaderCellDef> Symbol </th>
<td mat-cell *matCellDef="let element"> {{element.symbol}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
.ts
export interface PeriodicElement {
name: string
position: number
}
const ELEMENT_DATA: PeriodicElement[] = [
{ position: 1, name: 'Hydrogen' },
{ position: 2, name: 'Helium' },
{ position: 3, name: 'Lithium' },
{ position: 4, name: 'Beryllium' },
{ position: 5, name: 'Boron' },
{ position: 6, name: 'Carbon' },
{ position: 7, name: 'Nitrogen' },
{ position: 8, name: 'Oxygen' },
{ position: 9, name: 'Fluorine' },
{ position: 10, name: 'Neon' },
];
@Component({
selector: 'app-my',
templateUrl: './my.component.html',
styleUrls: ['./my.component.scss']
})
export class MyComponent implements OnInit {
displayedColumns: string[] = ['position', 'name'];
dataSource = ELEMENT_DATA;
}