md-table in Angular Material 2
Asked Answered
S

2

13

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 ?

Samadhi answered 9/7, 2017 at 14:58 Comment(4)
Be sure to add MdTableModule in your imports (NgModule).Fencesitter
@Fencesitter Yes, I added before itselfSamadhi
can you provide whole html for table definition?Astigmatism
@DavidGabrichidze I just copy paste the whole html,ts and css from angular material table.Samadhi
P
25

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

Include this module in your app's imports

Prat answered 9/7, 2017 at 15:42 Comment(1)
Awesome, Thank you!Samadhi
B
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.

Bute answered 9/8, 2017 at 8:22 Comment(1)
Needs to be import { CdkTableModule } from '@angular/cdk/table';Mcdougall

© 2022 - 2024 — McMap. All rights reserved.