I am using material pagination to display some data
When I press on buttons they do not behave as expected, the browser seems to be giving some tips however I am a beginner and not really understanding what to do yet.
I was following an online tutorial here that I found on stack overflow pertaining this
https://stackblitz.com/edit/angular-2liy7w?file=app%2Fpaginator-configurable-example.ts,app%2Fpaginator-configurable-example.html
Here is my code
import { Component, OnInit, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { PostServiceService } from '../post-service.service';
import { Subject, Observable, map } from "rxjs";
import * as _ from 'lodash';
import {MatPaginatorIntl, MatPaginatorModule, PageEvent} from '@angular/material/paginator';
import '@angular/material/core';
interface Post {
userId: number;
id: number;
title: string;
body: string;
}
@Component({
selector: 'app-post-list',
templateUrl: './post-list.component.html',
styleUrls: ['./post-list.component.css']
})
export class PostListComponent implements OnInit{
// Where posts are handled and displayed
posts$: any;
pageEvent: PageEvent;
activePageDataChunk = [];
length = 1000;
pageSize = 10;
pageSizeOptions = [5, 10, 25, 100];
ngOnInit() {
this.postService.getfirst_post()
.subscribe(posts => {this.posts$ = posts
this.activePageDataChunk = this.posts$.slice(0, this.pageSize)
}
);
}
constructor(private postService: PostServiceService) {
//this.activePageDataChunk = this.posts$.slice(0, this.pageSize)
}
setPageSizeOptions(setPageSizeOptionsInput: string) {
this.pageSizeOptions = setPageSizeOptionsInput.split(',').map(str => +str);
}
onPageChanged(e) {
let firstCut = e.pageIndex * e.pageSize;
let secondCut = firstCut + e.pageSize;
this.activePageDataChunk = this.posts$.slice(firstCut, secondCut);
}
}