I am new in angular 5 development. I am trying to develop a data table with angular material using the example provided here: "https://material.angular.io/components/table/examples".
I am getting an error saying Can't bind to 'dataSource' since it isn't a known property of 'table'.
Please help.
Please see your dataSource varibale doesn't get the data from the server or dataSource is not assigned to the expected format of data.
Thanx to @Jota.Toledo, I got the solution for my table creation. Please find the working code below:
component.html
:component.ts
:app.module.ts
:Remember to import the MatTableModule module and remove the table element show below for reference.
wrong implementation
<table mat-table [dataSource]=”myDataArray”> ... </table>
correct implementation:
<mat-table [dataSource]="myDataArray"> </mat-table>
I had this issue when running
ng test
, so to fix it, I added to myxyz.component.spec.ts
file:import { MatTableModule } from '@angular/material';
And added it to
imports
section inTestBed.configureTestingModule({})
:Remember to add
MatTableModule
in yourapp.module's imports
The problem is your angular material version, I have the same, and I have resolved this when I have installed the good version of angular material in local.
Hope it solve yours too.