Table Paginator is not working as expected - json

I am fetching the data from the server, the data is coming well and showing in the but the paginator is not working although it is only showing.
The paginator is showing the webpage but it is not working as the next button, go to page etc.
<div class="container">
<div class="row">
<div class="col my-3">
<div class="mat-elevation-z8">
<app-message></app-message>
<table mat-table [dataSource]="dataSource">
<!-- Position Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let element"> {{element.name}}</td>
</ng-container>
<!-- Position Column -->
<ng-container matColumnDef="phone">
<th mat-header-cell *matHeaderCellDef> Phone </th>
<td mat-cell *matCellDef="let element"> {{element.phone}}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<mat-paginator [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
</div>
</div>
</div>
</div>
This is the TS code.
export class UsersComponent implements OnInit {
displayedColumns: string[] = ['name', 'phone'];
dataSource = new MatTableDataSource<PeriodicElement>([]);
#ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
constructor(public data: DataService, private rest: RestApiService) {}
ngOnInit() {
this.getUsers();
this.dataSource.paginator = this.paginator;
}
async getUsers(){
try {
const data =await this.rest.get("http://localhost:3030/user/auth/all/users");
if(data['status']) {
console.log(data['data']);
this.dataSource = data['data'];
} else {
this.data.error(data['message']);
}
} catch (error) {
this.data.error(error['message']);
}
}
}
interface PeriodicElement {
slno:number,
name: string,
phone: string
}
const dataArray: PeriodicElement[] = [];

Can u integrate AfterViewInit and call this
ngAfterViewInit() {
this.dataSource.paginator = this.paginator;
}
and change
this.dataSource = data['data'];
to
this.dataSource.data = data['data'];

Make sure you import MatPaginator from #angular/material/paginator not #angular/material

Seems like you have not added the corresponding table and paginator modules inside your app.module.ts
app.module.ts
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { FormsModule } from '#angular/forms';
import {MatTableModule} from '#angular/material/table';
import {MatPaginatorModule} from '#angular/material/paginator';
import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';
#NgModule({
imports: [ BrowserModule, FormsModule, MatTableModule,MatPaginatorModule ],
declarations: [ AppComponent, HelloComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
As your code was not working even on stackblitz, so i have added dummy data to show you an example. Please find stackblitz here: https://stackblitz.com/edit/angular-tcgvnu

Related

Merge two Observables and pass into dataSource as a single Observable for Angular material table

I am fairly new to Web development and am stuck on this problem from past some days, Would appreciate a heck lot if the community could help me out here
I want to merge two observables coming out of firebase database, I want to join them concurrently i.e
3 rows of the first observable to be mapped with the three rows from the other observable. I want to use this observable into my dataSource for Angular Mat Table. and extract fields from both the observable here
This is the Component.ts
import { Component, OnInit } from '#angular/core';
import { ProductService } from 'src/app/product.service';
import { Observable, observable } from 'rxjs';
import "rxjs/add/observable/zip";
import "rxjs/add/observable/forkJoin";
#Component({
selector: 'app-admin-products',
templateUrl: './admin-products.component.html',
styleUrls: ['./admin-products.component.css']
})
export class AdminProductsComponent implements OnInit {
products$:Observable<any[]>
productsKey$:Observable<any[]>
finalProduct$
list:[]
constructor(private productService:ProductService) {
this.products$ = this.productService.getAll().valueChanges();
this.productsKey$ = this.productService.getAll().snapshotChanges();
//this.finalProduct$ = (this.products$).pipe(merge(this.productsKey$));
}
displayedColumns = ['title','price','edit'];
// dataSource = this.products$
ngOnInit(): void {
}
}
This is the service.ts
import { Injectable } from '#angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
#Injectable({
providedIn: 'root'
})
export class ProductService {
constructor(private db:AngularFireDatabase) { }
create(product){
console.log(product)
return this.db.list('/products').push(product);
}
getAll(){
return this.db.list('/products')
}
}
this is the final HTML markup
<p style="padding: 50px;">
<button mat-flat-button color="primary" routerLink="/admin/products/new" > Add New Product</button>
</p>
<mat-table [dataSource]="finalProduct$ | async" class="mat-elevation-z8">
<!-- Position Column -->
<ng-container matColumnDef="title">
<mat-header-cell *matHeaderCellDef> Title </mat-header-cell>
<mat-cell *matCellDef="let element"> {{ element.title }} </mat-cell>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="price">
<mat-header-cell *matHeaderCellDef> Price </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.price}}</mat-cell>
</ng-container>
<ng-container matColumnDef="edit">
<mat-header-cell *matHeaderCellDef> </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element | json}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
The first Observable products$ has data in this format
{category: "bread", imageUrl: "https://pixabay.com/photos/bread-food-isolated-croissant-loaf-4592483/", price: 50, title: "Freshly Baked Bread"}
the Second observable productsKey$ has data in this format
{payload: DataSnapshot, type: "value", prevKey: null, key: "-M9HwZl_WYfgTchxanrb"}
I wish to extract the Price, title and key value from these observables and display them in a table.
I would suggest using zip which does exactly what you want, i.e merge 2 observables.
ngOnInit(): void {
zip(this.products$, this.productsKey$).pipe(
map(reponse => { return {...reponse[0], ...response[1]}})
).subscribe(
reponse => {
this.dataSource = reponse;
});
You can also use combineLatest as Michael suggested with slight modifications. Change map(reponse => [...reponse[0], ...response[1]]) to map(reponse => { return {...reponse[0], ...response[1]}})
If the observables are independent of each other you could use RxJS combineLatest() function to combine multiple observables.
displayedColumns = ['title', 'price', 'edit'];
constructor(private productService: ProductService) {
this.products$ = this.productService.getAll().valueChanges();
this.productsKey$ = this.productService.getAll().snapshotChanges();
}
ngOnInit(): void {
combineLatest(this.products$, this.productsKey$).pipe(
take(1), // <-- remove it if the data stream needs to persist
map(reponse => [...reponse[0], ...response[1]])
).subscribe(
reponse => {
this.dataSource = reponse;
}
);
}

Angular dynamically populate table

I'm trying to dynamically populate a table using the following code:
teams.component.ts
import { Component, OnInit } from '#angular/core';
import { first } from 'rxjs/operators';
import { TeamService } from 'src/app/services/team.service';
export interface PeriodicElement {
name: string;
position: number;
weight: number;
symbol: string;
}
#Component({
selector: 'app-teams',
templateUrl: './teams.component.html',
styleUrls: ['./teams.component.scss']
})
export class TeamsComponent implements OnInit {
public teams : any;
tableCols = ['id', 'name'];
constructor(private teamService : TeamService) { }
ngOnInit(): void {
this.teamService.getTeams().pipe(first()).subscribe(
data => {
this.teams = data.results
},
error => {
console.log(error.error)
}
)
}
}
teams.component.html
<app-table [tableData]="teams" [tableColumns]="tableCols"></app-table>
table.component.ts
import { Component, OnInit, Input, ViewChild } from '#angular/core';
import { MatSort } from '#angular/material/sort';
import { MatPaginator } from '#angular/material/paginator';
import { MatTableDataSource } from '#angular/material/table';
#Component({
selector: 'app-table',
templateUrl: './table.component.html',
styleUrls: ['./table.component.scss']
})
export class TableComponent implements OnInit {
tableDataSrc: any;
// tslint:disable-next-line: no-input-rename
#Input('tableColumns') tableCols: string[];
#Input() tableData: {}[] = [];
#ViewChild(MatSort, { static: true }) sort: MatSort;
#ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
constructor() { }
ngOnInit() {
this.tableDataSrc = new MatTableDataSource(this.tableData);
this.tableDataSrc.sort = this.sort;
this.tableDataSrc.paginator = this.paginator;
}
}
table.component.html
<div class="mat-elevation-z8">
<table mat-table [dataSource]="tableDataSrc" matSort class="mat-elevation-z8">
<ng-container *ngFor="let col of tableCols">
<ng-container matColumnDef="{{ col }}">
<th mat-header-cell *matHeaderCellDef mat-sort-header>
{{ col | titlecase }}
</th>
<td mat-cell *matCellDef="let profile">{{ profile }}</td>
</ng-container>
</ng-container>
<tr mat-header-row *matHeaderRowDef="tableCols"></tr>
<tr mat-row *matRowDef="let row; columns: tableCols"></tr>
</table>
<mat-paginator [pageSizeOptions]="[1, 2, 3, 5, 10, 20]" showFirstLastButtons></mat-paginator>
</div>
A 'team' object looks like the following:
{'id': 9, 'name': 'FC Barcelona'} and the teams variable is a list of these objects.
When I navigate to the teams page the table is rendered and stays empty, what am I doing wrong here?
try replacing this part in table.component.ts
ngOnInit() {
this.tableDataSrc = new MatTableDataSource(this.tableData);
this.tableDataSrc.sort = this.sort;
this.tableDataSrc.paginator = this.paginator;
}
with this
ngOnChanges(changes: SimpleChanges) {
if(changes.tableData.currentValue) {
this.tableDataSrc = new MatTableDataSource(this.tableData);
this.tableDataSrc.sort = this.sort;
this.tableDataSrc.paginator = this.paginator;
}
}
The problem is teams field in TeamsComponent gets initialized after (due to async operation) TableComponents OnInit phase. If you change ngOnInit with ngOnChanges whenever teams field changes TableComponent becomes aware of it.
Further reading: https://angular.io/guide/lifecycle-hooks#using-change-detection-hooks

mat-table won't get filled with data from restservice

I am getting an array from my restservice. This is working and some information of the response I am printing on the page. But strangely I cannot fill my mat-table and I don't know why.The mat-table was working before, I am just not putting the data in it the right way. Every help will be appreciated.
table-paginator-component.ts:
import {Component, OnInit, ViewChild} from '#angular/core';
import {MatPaginator} from '#angular/material/paginator';
import {MatTableDataSource} from '#angular/material/table';
import {HttpService} from '../http.service';
import { HttpClient } from '#angular/common/http';
import {AreaCode} from '../models/areacode';
#Component({
// tslint:disable-next-line: component-selector
selector: 'table-paginator',
styleUrls: ['table-paginator.component.css'],
templateUrl: 'table-paginator.component.html',
})
export class TablePaginatorComponent implements OnInit {
displayedColumns: string[] = ['standort', 'stammnummer', 'bereich'];
products = [];
dataSource = new MatTableDataSource<any>(this.products);
constructor(private httpClient: HttpClient) {
this.getAreaCodes();
}
#ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
ngOnInit() {
this.dataSource.paginator = this.paginator;
}
getAreaCodes() {
this.httpClient.get('http://localhost:8080/phonenumbersmanagement/api/v1/areacodes/all')
.subscribe((res:
any[]) => {
console.log(res);
this.products = res;
});
}
}
table-paginator.component.html:
<!-- <button (click)="getAreaCodes2()">GET /productss</button> -->
<ul>
<li *ngFor="let product of products" >
-- id: {{product.id}}
-- name: {{product.title}}
-- base: {{product.base}}
</li>
</ul>
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource">
<!-- Position Column -->
<ng-container matColumnDef="standort">
<th mat-header-cell *matHeaderCellDef> Standort </th>
<td mat-cell *matCellDef="let element"> {{element.title}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="stammnummer">
<th mat-header-cell *matHeaderCellDef> Stammnummer </th>
<td mat-cell *matCellDef="let element"> {{element.title}} </td>
</ng-container>
<!-- Weight Column -->
<ng-container matColumnDef="bereich">
<th mat-header-cell *matHeaderCellDef> Bereich </th>
<td mat-cell *matCellDef="let element"> {{element.title}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<mat-paginator [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
</div>
Current Output:
try with this.products = res;
this.datasource.data = res;
Change your getAreaCodes method like below,
getAreaCodes() {
this.httpClient.get('http://localhost:8080/phonenumbersmanagement/api/v1/areacodes/all')
.subscribe((res: any[]) => {
this.products = res;
this.dataSource = new MatTableDataSource(res);
});
}
Update your mat-paginator with length as like property binding.
<mat-paginator [length]="products.length" [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
I think that, when you receive data from api and add result value to products variable then datasource variable dont update.
Try to use products variable on html table tag-> [dataSource]="products"
This thing worked for me. import table from angular/material and create an
instance of it using viewchild. get your user data and set displayedColumns in ngOnInit(), In ngAfterContentChecked() you need to create MatTableDataSource instance and set this instance to table.dataSource in ngAfterViewInit() check below
import { MatTable, MatTableDataSource } from '#angular/material/table';
export class GetUserComponent implements OnInit {
#ViewChild(MatTable, {static:false}) table: MatTable<any>;
dataSource :any;
constructor(private appService:AppService){}
ngOnInit() {
this.appService.getUsers().subscribe(data => {
this.userData= data;
});
this.displayedColumns = ['select','title','content'];
}
ngAfterViewInit() {
this.table.dataSource = this.dataSource;
}
ngAfterContentChecked(){
this.dataSource = new MatTableDataSource (this.userData);
}
}
you can check my stackblitz here
https://stackblitz.com/edit/angular-dynamicexamples

I'm getting a "this.container is undefined" error when using mat-paginator

I have a mat-table that has a list of users called from a database using a spring REST API which works perfectly but when I wanted to add a paginator to help go through the whole list of users I started getting a "this.container is undefined" error when trying to click on the paginator.
Also, for some reason It showing "Items per page: 5" only even though I have almost 27 users.
Here's my html code:
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter" style="width: 500px !important">
</mat-form-field>
<mat-table class="lessons-table mat-elevation-z8" [dataSource]="dataSource">
<ng-container matColumnDef="id" class=".mat-column-id">
<mat-header-cell *matHeaderCellDef>#</mat-header-cell>
<mat-cell *matCellDef="let user">{{user.id}}</mat-cell>
</ng-container>
<ng-container matColumnDef="username" class=".mat-column-username">
<mat-header-cell *matHeaderCellDef>Username</mat-header-cell>
<mat-cell class="description-cell" *matCellDef="let user">{{user.username}}</mat-cell>
</ng-container>
<ng-container matColumnDef="email" class=".mat-column-email">
<mat-header-cell *matHeaderCellDef>Email</mat-header-cell>
<mat-cell class="duration-cell" *matCellDef="let user">{{user.email}}</mat-cell>
</ng-container>
<ng-container matColumnDef="firstname" class=".mat-column-name">
<mat-header-cell *matHeaderCellDef>firstname</mat-header-cell>
<mat-cell class="duration-cell" *matCellDef="let user">{{user.firstName}}</mat-cell>
</ng-container>
<ng-container matColumnDef="lastname"class=".mat-column-name">
<mat-header-cell *matHeaderCellDef>Last Name</mat-header-cell>
<mat-cell class="duration-cell" *matCellDef="let user">{{user.lastName}}</mat-cell>
</ng-container>
<ng-container matColumnDef="enabled" class=".mat-column-enabled">
<mat-header-cell *matHeaderCellDef>Enabled</mat-header-cell>
<mat-cell class="duration-cell" *matCellDef="let user">{{user.enabled}}</mat-cell>
</ng-container>
<ng-container matColumnDef="registeredDate" class=".mat-column-date">
<mat-header-cell *matHeaderCellDef>Registered Date</mat-header-cell>
<mat-cell class="duration-cell" *matCellDef="let user">{{user.registeredDate | date: shortDate}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></mat-header-row>
<mat-row class="mat-row" *matRowDef="let row; columns: displayedColumns" (click)="onRowClicked(row)"></mat-row>
</mat-table>
<mat-paginator [pageSizeOptions]="[5, 10, 25, 100]"></mat-paginator>
and the ts file:
import { Component, OnInit, ViewChild } from '#angular/core';
import { ViewEncapsulation } from '#angular/core';
import { HttpClient, HttpHeaders } from '#angular/common/http';
import { UserService } from '../user.service';
import { MatDialog, MatDialogConfig, MatTableDataSource, MatPaginator, MatSort } from '#angular/material';
import { NewDialogComponent } from '../new-dialog/new-dialog.component';
import { DomSanitizer } from '#angular/platform-browser';
import { map } from 'rxjs-compat/operator/map';
import { Observable, Observer } from 'rxjs';
#Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['../app.component.scss', './dashboard.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class DashboardComponent implements OnInit {
loginuser: any = {};
imgSrc: any = {};
users: any[] = [];
imageToShow: any;
public dataSource = new MatTableDataSource<User>();
displayedColumns = ['id', 'username', 'email', 'firstname', 'lastname', 'registeredDate', 'enabled'];
#ViewChild(MatPaginator) paginator: MatPaginator;
#ViewChild(MatSort) sort: MatSort;
constructor(private service: UserService, private http: HttpClient, private sanitizer: DomSanitizer) {
this.loginuser = JSON.parse(localStorage.getItem('currentUser'));
this.service.getAllUsers(this.loginuser.token).subscribe(u => {
this.dataSource.data = u as User[];
this.users = u;
// console.log('user: ', this.users);
});
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
ngOnInit() {
}
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
if (this.dataSource.paginator) {
this.dataSource.paginator.firstPage();
}
}
}
The value of this injected member variable is not immediately available at component construction time!
Angular will fill in this property automatically, but only later in the component lifecycle, after the view initialization is completed.
If we want to write component initialization code that uses the references injected by #ViewChild, we need to do it inside the AfterViewInit lifecycle hook.
#Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent implements AfterViewInit {
#ViewChild(SomeComponent)
someComponent: SomeComponent;
ngAfterViewInit() {
console.log('Values on ngAfterViewInit():');
console.log("someComponent:", this.someComponent);
}
}
In Your case just put these two line in NgAfterViewInit LifeCyle as:
import { Component, OnInit, ViewChild } from '#angular/core';
import { ViewEncapsulation } from '#angular/core';
import { HttpClient, HttpHeaders } from '#angular/common/http';
import { UserService } from '../user.service';
import { MatDialog, MatDialogConfig, MatTableDataSource, MatPaginator, MatSort } from '#angular/material';
import { NewDialogComponent } from '../new-dialog/new-dialog.component';
import { DomSanitizer } from '#angular/platform-browser';
import { map } from 'rxjs-compat/operator/map';
import { Observable, Observer } from 'rxjs';
#Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['../app.component.scss', './dashboard.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class DashboardComponent implements OnInit, AfterViewInit {
loginuser: any = {};
imgSrc: any = {};
users: any[] = [];
imageToShow: any;
public dataSource = new MatTableDataSource<User>();
displayedColumns = ['id', 'username', 'email', 'firstname', 'lastname', 'registeredDate', 'enabled'];
#ViewChild(MatPaginator) paginator: MatPaginator;
#ViewChild(MatSort) sort: MatSort;
constructor(private service: UserService, private http: HttpClient, private sanitizer: DomSanitizer) {
this.loginuser = JSON.parse(localStorage.getItem('currentUser'));
this.service.getAllUsers(this.loginuser.token).subscribe(u => {
this.dataSource.data = u as User[];
this.users = u;
// console.log('user: ', this.users);
});
ngAfterViewInit() {
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
}

Angular Material table: can't bind to 'matRowDefColumn'

I am trying to use an Angular Material table. I imported the module but I get a template parse error.
HTML:
<mat-table [dataSource]="dataSource">
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
<mat-cell *matCellDef="let project">{{project.name}}</mat-cell>
</ng-container>
<ng-container matColumnDef="key">
<mat-header-cell *matHeaderCellDef> Key </mat-header-cell>
<mat-cell *matCellDef="let project">{{project.Key}}</mat-cell>
</ng-container>
<ng-container matColumnDef="reason">
<mat-header-cell *matHeaderCellDef> reason </mat-header-cell>
<mat-cell *matCellDef="let project">{{project.reason}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; column: displayedColumns;"></mat-row>
</mat-table>
Imports in the component:
import { Component, OnInit } from '#angular/core';
import {Observable} from "rxjs"
import { HttpClient, HttpErrorResponse } from '#angular/common/http';
import { ProjectService } from '../services/project.service';
import { UserService } from '../services/user.service';
import { Subject } from 'rxjs/Subject';
import { DataSource } from '#angular/cdk/collections';
DataSource: I return an Array as an Observable with the returnDeadProjectList()
export class ProjectDataSource extends DataSource<any>{
constructor(private project:ProjectComponent){
super();
}
connect(): Observable<Project[]>{
return this.project.returnDeadProjectList();
}
disconnect(){}
Imports from app.module.ts:
import { BrowserModule } from '#angular/platform-browser';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '#angular/core';
import { HttpClientModule } from '#angular/common/http';
import { CommonModule } from "#angular/common";
import 'hammerjs';
import { ProjectService } from './services/project.service';
import { UserService } from './services/user.service';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { FormsModule } from '#angular/forms';
import { MatInputModule, MatButtonModule, MatExpansionModule, MatDatepickerModule, MatNativeDateModule, MatToolbarModule, MatListModule, MatIconModule, MatProgressSpinnerModule, MatSlideToggleModule, MatTableModule, MatPaginatorModule } from '#angular/material';
import { AppComponent } from './app.component';
import { MyFormComponent } from './my-form/my-form.component';
import { BitbucketComponent } from './bitbucket/bitbucket.component';
import { UserComponent } from './user/user.component';
import { ProjectComponent } from './project/project.component';
import { CdkTableModule } from '#angular/cdk/table';
The error I get is:
compiler.js:466 Uncaught Error: Template parse errors:
Can't bind to 'matRowDefColumn' since it isn't a known property of 'mat-row'.
1. If 'mat-row' is an Angular component and it has 'matRowDefColumn' input, then verify that it is part of this module.
2. If 'mat-row' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '#NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '#NgModule.schemas' of this component.
If I write the CUSTOM_ELEMENTS_SCHEMA in schemas: [ ], I get an different error:
compiler.js:466 Uncaught Error: Template parse errors:
Property binding matRowDefColumn not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "#NgModule.declarations". ("` `<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
[ERROR ->]<mat-row *matRowDef="let row; column: displayedColumns;"></mat-row>
Has someone an idea what I am missing? I should have all the imports I need but somehow it can't find the elements. Furthermore, I don't even use matHeaderRowDef
The code snippet
<mat-row *matRowDef="let row; column: displayedColumns;"></mat-row>
has a issue with the property name. MatRowDef has property columns not column.
Change it to
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row> and it should work after that.
Add this code in your .component.ts and in app.module.shared.ts.
It works for me
import {
MatPaginator, MatSort, MatTable, MatTableModule, MatTabHeader,
MatHeaderRow, MatHeaderCell, MatHeaderCellDef, MatHeaderRowDef,
MatSortHeader, MatRow, MatRowDef, MatCell, MatCellDef,
_MatCell, _MatCellDef, _MatHeaderCellDef, _MatHeaderRowDef
} from '#angular/material';
#NgModule({
imports: [MatPaginator, MatSort, TableDataSource,
CdkTableModule, MatTable, MatTableModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
declarations: [
MatTabHeader,
MatHeaderRow,
MatHeaderCell,
MatHeaderCellDef,
MatHeaderRowDef,
MatSortHeader,
MatRow,
MatRowDef,
MatCell,
MatCellDef,
_MatCell,
_MatCellDef,
_MatHeaderCellDef,
_MatHeaderRowDef
]
})