md-table in Angular Material 2

南笙酒味 提交于 2019-12-05 13:45:07

问题


I am working with Angular Material Table. In Html code, there is

<ng-container cdkColumnDef="userId">
  <md-header-cell *cdkHeaderCellDef> ID </md-header-cell>
  <md-cell *cdkCellDef="let row"> {{row.id}} </md-cell>
</ng-container>

I found out that cdkHeaderCellDef and cdkCellDef are from CDK Table

I am getting error saying "Can't bind to 'cdkHeaderRowDef' since it isn't a known property of 'md-header-row'."

How can I solve this ?


回答1:


The cdkHeaderCellDef and cdkCellDef are part of the @angular/cdk library and exported in the CdkTableModule.

Include this module in your app's imports




回答2:


 import { CdkTableModule } from '@angular/cdk';

add this to the top of your component and to the top of app.module.ts and then on app.module.ts add CdkTableModule to imports as given below.

@NgModule({
   declarations: [

],
imports: [
    CdkTableModule

],
providers: [

],
bootstrap: [AppComponent],
})

there may be declarations and providers but in the above snippet they are ignored for convenience.



来源:https://stackoverflow.com/questions/44997756/md-table-in-angular-material-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!