【发布时间】:2018-05-08 08:17:47
【问题描述】:
我一直有这个错误
未捕获的错误:模块“MaterialModule”导入了意外的指令“MatPaginator”。请添加@NgModule 注解。
这是我的材料模块
import { NgModule, ViewChild } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatPaginator, MatSort, MatTableDataSource,MatButtonModule,
MatTableModule } from '@angular/material';
@NgModule({
imports: [MatButtonModule,MatTableModule,
MatPaginator, MatSort,
MatTableDataSource],
exports: [MatButtonModule,MatTableModule,MatPaginator, MatSort,
MatTableDataSource],
})
export class MaterialModule { }
这是我的 app.module
...
import { MaterialModule } from './material.module';
@NgModule({
declarations: [
...
],
imports: [
...
MaterialModule,
...
],
providers: [...],
bootstrap: [ AppComponent]
})
export class AppModule { }
这也是我的看法
<div class="example-container mat-elevation-z8">
<div class="example-header">
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)"
placeholder="Filter">
</mat-form-field>
</div>
<!-- Name Column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.name}} </mat-cell>
</ng-container>
<!-- Weight Column -->
<ng-container matColumnDef="email">
<mat-header-cell *matHeaderCellDef> email </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.email}} </mat-cell>
</ng-container>
<!-- Color Column -->
<ng-container matColumnDef="phone">
<mat-header-cell *matHeaderCellDef> phone </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.phone}} </mat-cell>
</ng-container>
<ng-container matColumnDef="company">
<mat-header-cell *matHeaderCellDef> company </mat-header-cell>
<mat-cell *matCellDef="let user"> {{user.company.name}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
我从angular material documentation 拿走了它,我该如何解决?
【问题讨论】:
-
我会导入
MatPaginatorModule -
我已经导入了,还是出现这个错误
-
您是否从
imports中删除了MatPaginator? -
是的,我会更新帖子
-
我从 Angular Material 文档中获取了它
标签: angular typescript