Angular Simple Pagination Example | ngx-pagination

By Hardik Savani October 20, 2023 Category : Angular


This article will give you an example of angular simple pagination example. I would like to show you angular 13 simple pagination examples. you'll learn angular ngx-pagination example. you can see the angular ngx pagination example. Let's get started with simple pagination in angular.

In this tutorial, I will give you step by step simple pagination example using ngx-pagination npm package which you can use in angular 8, angular 9, angular 10, angular 11, angular 12, and angular 13. so let's follow bellow step to make this example.

Step 1: Create New App

You can easily create your angular app using bellow command:

ng new my-new-app

Step 2: Install ngx-pagination

In this step, we will install ngx-pagination package. let's install by following command:

npm install ngx-pagination --save

Step 3: Import Modules

In this step, we need to import HttpClientModule and NgxPaginationModule to app.module.ts file. so let's import it as like bellow:


import { BrowserModule } from '@angular/platform-browser';

import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

import { HttpClientModule } from '@angular/common/http';

import { NgxPaginationModule } from 'ngx-pagination';


declarations: [



imports: [





providers: [],

bootstrap: [AppComponent]


export class AppModule { }

Step 4: Create Service for API

Here, we need to create service for http client request. we will create service file and write client http request code. this service will use in our component file. So let's create service and put bellow code:

ng g s services/post

Now let's add code as like bellow:


import { Injectable } from '@angular/core';

import { HttpClient } from '@angular/common/http';


providedIn: 'root'


export class PostService {

private url = '';

constructor(private httpClient: HttpClient) { }


return this.httpClient.get(this.url);



Step 5: Use Service to Component

Now we have to use this services to our app component. So let's updated code as like bellow:


import { Component, OnInit } from '@angular/core';

import { PostService } from './services/post.service';


selector: 'app-root',

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']


export class AppComponent implements OnInit {


p: number = 1;

constructor(private service:PostService) {}

ngOnInit() {


.subscribe(response => {

this.posts = response;




Step 6: Updated View File

Now here, we will updated our html file. let's put bellow code:


<h1>Angular Pagination Example -</h1>

<ul class="list-group">


*ngFor="let post of posts| paginate: { itemsPerPage: 10, currentPage: p }"


{{ post.title }}



<pagination-controls (pageChange)="p = $event"></pagination-controls>

Run Angular App:

All the required steps have been done, now you have to type the given below command and hit enter to run the Angular app:

ng serve

Now, Go to your web browser, type the given URL and view the app output:


you will see layout as bellow:

I hope it can help you...

Tags :