I\'m new to angular and trying to implement pagination in my app. I am trying to use this material component.
With the code below, I can get length,
This issue is resolved after spending few hours and i got it working. which is believe is the simplest way to solve the pagination with angular material. - Do first start by working on (component.html) file
and do in the (component.ts) file
import { MatPaginator } from '@angular/material/paginator';
import { Component, OnInit, ViewChild } from '@angular/core';
export interface UserData {
full_name: string;
email: string;
mob_number: string;
}
export class UserManagementComponent implements OnInit{
dataSource : MatTableDataSource;
@ViewChild(MatPaginator) paginator: MatPaginator;
constructor(){
this.userList();
}
ngOnInit() { }
public userList() {
this._userManagementService.userListing().subscribe(
response => {
console.log(response['results']);
this.dataSource = new MatTableDataSource(response['results']);
this.dataSource.paginator = this.paginator;
console.log(this.dataSource);
},
error => {});
}
}
Remember Must import the pagination module in your currently working module(module.ts) file.
import {MatPaginatorModule} from '@angular/material/paginator';
@NgModule({
imports: [MatPaginatorModule]
})
Hope it will Work for you.