我一直有这个错误
Uncaught Error: Unexpected directive 'MatPaginator' imported by the module 'MaterialModule'. Please add a @NgModule annotation.
这是我的 Material 模块
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
在我的@NgModule
进入导入数组。
它解决了我的问题。我希望它也适合你。
关于angular - Uncaught Error : Unexpected directive 'angular-material' imported by the module 'MyMaterialModule' . 请添加 @NgModule 注释。 Angular 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47471188/