簡體   English   中英

角材料找不到列

[英]angular material Could not find column

我有以下代碼,但我無緣無故地收到此錯誤:

ERROR 錯誤:找不到 ID 為“大洲”的列。

我已經添加了顯示列部分,所以我不確定為什么會出現此錯誤。

   <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([]);

你忘記了 th 和 td “mat-h​​eader”和“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>

你只寫

<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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM