How can I use the material design data table layout without a datasource (static data)? I can find no example for this use case on https://material.angular.io/components/table/examples. For example I tried the following without success.
<mat-table>
<mat-header-row>
<mat-header-cell>One</mat-header-cell>
<mat-header-cell>Two</mat-header-cell>
</mat-header-row>
<mat-row>
<mat-cell>aaa</mat-cell>
<mat-cell>bbb</mat-cell>
</mat-row>
</mat-table>
I'am getting following error:
LeistungenComponent.html:195 ERROR Error: StaticInjectorError(AppModule)[MatCell -> CdkColumnDef]:
StaticInjectorError(Platform: core)[MatCell -> CdkColumnDef]:
NullInjectorError: No provider for CdkColumnDef!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:979)
at resolveToken (core.js:1232)
at tryResolveToken (core.js:1182)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1077)
at resolveToken (core.js:1232)
at tryResolveToken (core.js:1182)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1077)
at resolveNgModuleDep (core.js:9238)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:9919)
at resolveNgModuleDep (core.js:9238)
In your app.module.ts, add to providers
providers:[CdkColumnDef]
Add to the imports
import { CdkColumnDef } from '@angular/cdk/table';
As far as I know you cannot use Material Table like a normal HTML table. You would need a datasource.
There are two ways to get the styles of Material Table though. You can either use Material Design Lite or by using the css styles from Material Table.
Please refer to this Git Hub thread for solution. https://github.com/angular/material2/issues/3805
<style>
.mat-table {
display: block;
font-family: Tahoma, Verdana;
}
.mat-row,
.mat-header-row {
display: flex;
border-bottom-width: 1px;
border-bottom-style: solid;
align-items: center;
min-height: 48px;
padding: 0 24px;
}
.mat-cell,
.mat-header-cell {
flex: 1;
overflow: hidden;
word-wrap: break-word;
}
</style>
<div class="mat-table">
<div class="mat-header-row">
<div class="mat-header-cell">One</div>
<div class="mat-header-cell">Two</div>
<div class="mat-header-cell">Three</div>
</div>
<div class="mat-row">
<div class="mat-cell">AAA</div>
<div class="mat-cell">BBB</div>
<div class="mat-cell">CCC</div>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With