import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { MatIconModule } from '@angular/material/icon'; import { MatTableModule } from '@angular/material/table';
@NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule, MatIconModule, MatTableModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
如果你在其他模块中使用了 MatTable,你需要在那些模块中导入 MatTableModule。
如果你的组件使用到 MatTable,确保在组件的 .ts 和 .html 文件中都正确引入了 MatTable:
import { Component } from '@angular/core';
@Component({ selector: 'app-example-table', templateUrl: './example-table.component.html', styleUrls: ['./example-table.component.css'] }) export class ExampleTableComponent {
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; dataSource = ELEMENT_DATA;
}