Angular table material 无法编译:意外的结束标记 "ng-container"
Angular table material won't complie: Unexpected closing tag "ng-container"
我正在处理 n 个 Angular 项目集成 angular material5.2.5:
这是我的 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:我已经为 angular material 配置了模块。但我收到此错误:
有什么帮助吗?
上面的问题是你在{{element.lastName}}
之后没有关闭<mat-cell>
。这是更正后的代码,
注意:您可以在 visual studio 代码上使用自动套用格式来查看缺少的结束标记。
<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>
我正在处理 n 个 Angular 项目集成 angular material5.2.5: 这是我的 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:我已经为 angular material 配置了模块。但我收到此错误:
有什么帮助吗?
上面的问题是你在{{element.lastName}}
之后没有关闭<mat-cell>
。这是更正后的代码,
注意:您可以在 visual studio 代码上使用自动套用格式来查看缺少的结束标记。
<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>