Angular7 - Can't bind to 'dataSource' since it isn't a known property of 'mat-table'

后端 未结 3 497
无人共我
无人共我 2021-01-12 11:47

I am using Angular 7.0.2, and I am facing this error while trying to create a table using Angular Material

Can\'t bind to \'dataSource\' since it isn\

相关标签:
3条回答
  • 2021-01-12 12:38

    If you think you did everything right by importing MatTableModule at app.module.ts like below

    import { MatTableModule } from '@angular/material';
    @NgModule({
      declarations: [
        AppComponent,
        TopBarComponent
      ],
      imports: [
        BrowserModule,
        AppRoutingModule,
        BrowserAnimationsModule,
        MatTableModule,
        CdkTableModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    

    and changing < table > to < meta-table > at html and it is still not working than have a look how you write your dataSource property tag.

    it has to be [dataSource] not [datasource]

    0 讨论(0)
  • 2021-01-12 12:42

    I would like to complete Sunil's answer: you should import MatTableModule and CdkTableModulein AppModule or in the Module where you component is declared.

    @NgModule({
      imports: [
        CdkTableModule,
        MatTableModule
        ...
      ]
    })
    public class AppModule
    
    0 讨论(0)
  • 2021-01-12 12:50

    You should import MatTableModule in AppModule or in the Module where you component is declared.

    @NgModule({
      imports: [
        MatTableModule
        ...
      ]
    })
    public class AppModule
    

    or

    @NgModule({
      imports: [
        MatTableModule
        ...
      ],
      declarations : [ProductionOrderComponent]
    })
    public class MyModule
    
    0 讨论(0)
提交回复
热议问题