[英]angular material Could not find column
I have the following code but I get this error for no reason:我有以下代码,但我无缘无故地收到此错误:
ERROR Error: Could not find column with id "continent".
ERROR 错误:找不到 ID 为“大洲”的列。
I already added the display column part so I am not sure why I am getting this error.我已经添加了显示列部分,所以我不确定为什么会出现此错误。
<div class="example-container mat-elevation-z8">
<mat-table #table [dataSource]="dataSource">
<ng-container matColumnDef="continentName">
<mat-header-cell *matHeaderCellDef>continentName </mat-
header-cell>
<mat-cell *matCellDef="let country"> {{country.continentName}} </mat-cell>
</ng-container>
<ng-container matColumnDef="countryName">
<mat-header-cell *matHeaderCellDef>countryName </mat-header-cell>
<mat-cell *matCellDef="let country"> {{country.countryName}} </mat-cell>
</ng-container>
<ng-container matColumnDef="areaInSqKm">
<mat-header-cell *matHeaderCellDef>areaInSqKm </mat-header-cell>
<mat-cell *matCellDef="let country"> {{country.areaInSqKm}} </mat-cell>
</ng-container>
<ng-container matColumnDef="population">
<mat-header-cell *matHeaderCellDef>population </mat-header-cell>
<mat-cell *matCellDef="let country"> {{country.population}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit {
title = "my-case-study";
displayedColumns =
['continentName','countryName','areaInSqKm','population'];
dataSource = new MatTableDataSource([]);
you forget th and td "mat-header" and "mat-cell" are directives of "th" and "td" eg你忘记了 th 和 td “mat-header”和“mat-cell”是“th”和“td”的指令,例如
<ng-container matColumnDef="continentName">
<th mat-header-cell *matHeaderCellDef>continentName </th>
<td mat-cell *matCellDef="let country"> {{country.continentName}} </td>
</ng-container>
You only write你只写
<ng-container matColumnDef="continentName">
<!--here missing "th"-->
<mat-header-cell *matHeaderCellDef>continentName </mat-
header-cell>
<!--here missing td-->
<mat-cell *matCellDef="let country"> {{country.continentName}} </mat-cell>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.