簡體   English   中英

角度表材料不符合要求:意外的結束標記“ng-container”

[英]Angular table material won't complie: Unexpected closing tag "ng-container"

我正在集成 angular material5.2.5 的 n Angular 項目:這是我的 app.component.ts:

import { Component } from '@angular/core';
import {MatTableDataSource} from '@angular/material';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
displayedColumns = ['position', 'firstName', 'lastName', 'email'];
dataSource = new MatTableDataSource(ELEMENT_DATA);
 }

  export interface Element {
   position: number;
   firstName: string;
   lastName: string;
   email: string;
     }

   const ELEMENT_DATA: Element[] = [
   {position: 1, firstName: 'John', lastName: 'Doe', email:       'john@gmail.com'},
    {position: 1, firstName: 'Mike', lastName: 'Hussey', email: 'mike@gmail.com'},
    {position: 1, firstName: 'Ricky', lastName: 'Hans', email: 'ricky@gmail.com'},
     {position: 1, firstName: 'Martin', lastName: 'Kos', email: 'martin@gmail.com'},
     {position: 1, firstName: 'Tom', lastName: 'Paisa', email: 'tom@gmail.com'}
   ];

這是我的 app.component.html:

 <mat-table #table [dataSource]="dataSource">
 <ng-container matColumnDef="position" >
 <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
 <mat-cell *matCellDef="let element">{{element.position}}</mat-cell>
 </ng-container>
 <ng-container matColumnDef="firstName">
 <mat-header-cell *matHeaderCellDef> First Name </mat-header-cell>
 <mat-cell *matCellDef="let element">{{element.firstName}}</mat-cell>
  </ng-container>
  <ng-container matColumnDef="lastName">
  <mat-header-cell *matHeaderCellDef> Last Name </mat-header-cell>
  <mat-cell *matCellDef="let element">{{element.lastName}}<mat-cell>
  </ng-container>
  <ng-container matColumnDef="email">
  <mat-header-cell *matHeaderCellDef> Email </mat-header-cell>
  <mat-cell *matCellDef="let element">{{element.email}}</mat-cell>
   </ng-container>
   <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
    <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
    </mat-table>

Ps:我已經為角材料配置了模塊。 但我收到此錯誤: 在此處輸入圖片說明

請問有什么幫助嗎?

上面的問題是您沒有在{{element.lastName}}之后關閉<mat-cell> 這是更正后的代碼,

注意:您可以在 Visual Studio 代碼上使用 AutoFormat 來查看缺少的結束標記。

<mat-table #table [dataSource]="dataSource">
  <ng-container matColumnDef="position">
    <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
    <mat-cell *matCellDef="let element">{{element.position}}</mat-cell>
  </ng-container>
  <ng-container matColumnDef="firstName">
    <mat-header-cell *matHeaderCellDef> First Name </mat-header-cell>
    <mat-cell *matCellDef="let element">{{element.firstName}}</mat-cell>
  </ng-container>
  <ng-container matColumnDef="lastName">
    <mat-header-cell *matHeaderCellDef> Last Name </mat-header-cell>
    <mat-cell *matCellDef="let element">{{element.lastName}}</mat-cell>
  </ng-container>
  <ng-container matColumnDef="email">
    <mat-header-cell *matHeaderCellDef> Email </mat-header-cell>
    <mat-cell *matCellDef="let element">{{element.email}}</mat-cell>
  </ng-container>
  <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
  <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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