Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

md-table in Angular Material 2

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 ?

like image 739
Chatra Avatar asked Jul 09 '17 14:07

Chatra


People also ask

What is * MatHeaderCellDef?

MatHeaderCellDef extends CdkHeaderCellDef Header cell definition for the mat-table. Captures the template of a column's header cell and as well as cell-specific properties. Selector: [matHeaderCellDef]

How do you refresh a mat-table?

Instead, when objects are added, removed, or moved on the data array, you can trigger an update to the table's rendered rows by calling its renderRows() method. So you just have to call renderRows() in your refresh() method to make your changes appears.

What is DataSource in mat-table?

A DataSource is simply a class that has at a minimum the following methods: connect and disconnect . The connect method will be called by the table to provide an Observable that emits the data array that should be rendered.


2 Answers

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

Include this module in your app's imports

like image 122
Andrew Seguin Avatar answered Oct 16 '22 22:10

Andrew Seguin


 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.

like image 2
Sithija Piyuman Thewa Hettige Avatar answered Oct 16 '22 20:10

Sithija Piyuman Thewa Hettige