How to use paginator from material angular?

后端 未结 9 1844
清歌不尽
清歌不尽 2020-12-04 11:14

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,

9条回答
  •  时光说笑
    2020-12-04 11:17

    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.

提交回复
热议问题