The most likely cause of this search result is a very long list of an array that needs to be displayed on the screen. Unless the backend architecture already implements server-side pagination of some sort, the displaying and formatting of data rest in the hand of the frontend engineer.
I recently got into a company and my first task was regarding a customer who complained of our retail service not displaying all of her customers. According to her, it takes a very long time to load. The first course of action was to examine the API that returned her customer object. A quick look at the console debunked the idea that it was a backend problem- since the array was returned in a reasonable time but... the array contained a list of 7000 customers!
This is a simple case for pagination. Writing a list of 7000 customers in a single is both bad UX and takes a lot of time to render to the browser. Pagination is simply the process of separating returned data or digital content into discrete pages. This is done both to enhance readability and reduce load time. NGX-pagination is an NPM package for pagination in angular. We would go step by step to show exactly how to use it.
To get started, we first of all need to install the package using NPM.
Next, we import it into the module where the target component is hosted and add it to the imports array. For this example, we would be using the main app module.
I have gone ahead to use a free rest API service to fetch a list for us to work with. After adding some CSS for styling, we currently have this as the result on display.
Taking a look at the console, we see that an array of 200 objects is being displayed. This same object has been rendered and displayed on the left side of the screen.
This is the HTML that renders the view.
Here, the *ngFor directive is being used to dynamically display all of the incoming objects. We need to include the pagination pipe just right after the *ngFor directive to paginate this array. NOTE that the PaginatePipe should be placed at the end of a *ngFor expression.
In the components HTML, we add in the pagination pipe and include a div to hold the pagination controls.
The paginate pipe at the very list must include:
In the ts file of the component, create a variable to hold the current page number. In this example, the variable used is "page".
After compilation, the page now appears as so:
We have successfully paginated the array of 200 objects into a very readable view of 12 objects per page.
This is a getting started guide to NGX-pagination. For a full list of all of its available customizations, visit the official page here.
View the source code for this tutorial here.
Hey, I’m Chidubem! I’m a software engineer who loves building cool stuff on the web. I’ve been coding for over four years, working mostly with JavaScript, TypeScript, React, and Node.js.
When I’m not deep in code, I’m sharing what I learn, mentoring newbies, or organizing events like Infotech Summit 2024 to help corpers break into tech. This is my little corner of the internet where I write about tech, ideas, and whatever else interests me. Stick around—there’s always something new to explore!
Trusted by businesses for clean code, modern design, and seamless user experiences.
“Working with Chidubem was a breath of fresh air. As a project manager, I value clear communication and timely delivery—he nailed both! Despite tight deadlines, he kept everything on track and delivered a seamless frontend experience. Would absolutely collaborate again.”
Product Manager, Wovenremit
“Chidubem brought my designs to life with pixel-perfect precision! I was amazed at how effortlessly he translated Figma files into smooth, responsive interfaces. He even provided great suggestions to enhance user experience. A true frontend expert!”
Product Designer, Glacr
“Chidubem is one of the most detail-oriented frontend engineers I’ve worked with. His ability to break down complex UI challenges and implement scalable, maintainable solutions is impressive. He writes clean, modular code, making collaboration seamless. Any team would be lucky to have him.”
Senior Mobile Engineer, Launch Legends
“Chidubem did an incredible job bringing Sterling Xperiences to life! He built a sleek, fast, and user-friendly website that perfectly reflects our brand. From design implementation to performance optimization, every detail was handled with excellence. I couldn’t be happier with the result!”
CEO, Sterling Experiences
“Working alongside Chidubem has been an amazing experience. He’s not just great at frontend development, but also incredibly supportive and collaborative. Whether it’s debugging tricky issues or brainstorming UX improvements, he always brings valuable insights to the table.”
Software Engineer, Yativo
“I’ve had the privilege of mentoring Chidubem and watching his growth as a frontend engineer. His technical skills, problem-solving ability, and dedication to excellence make him stand out. He’s more than ready for a full-time role, and any company that brings him on board will be gaining a valuable asset.”
Technology Executive
“What sets Chidubem apart, however, is his genuine enthusiasm and dedication to his work. He delivers high quality results and his effectiveness in meeting deadlines is impressive. He is a true asset to any team, and I highly recommend him for any opportunity.”
HR Specialist, Mavicon Investments
“It’s rare to find a frontend engineer who balances speed, quality, and maintainability so well. Chidubem’s code is clean, modular, and easy to scale. Our backend team had zero issues integrating his work, and performance metrics improved significantly.”
Developer Relations Manager, Moniepoint
“Working with Chidubem was a breath of fresh air. As a project manager, I value clear communication and timely delivery—he nailed both! Despite tight deadlines, he kept everything on track and delivered a seamless frontend experience. Would absolutely collaborate again.”
Product Manager, Wovenremit
“Chidubem brought my designs to life with pixel-perfect precision! I was amazed at how effortlessly he translated Figma files into smooth, responsive interfaces. He even provided great suggestions to enhance user experience. A true frontend expert!”
Product Designer, Glacr
“Chidubem is one of the most detail-oriented frontend engineers I’ve worked with. His ability to break down complex UI challenges and implement scalable, maintainable solutions is impressive. He writes clean, modular code, making collaboration seamless. Any team would be lucky to have him.”
Senior Mobile Engineer, Launch Legends
“Chidubem did an incredible job bringing Sterling Xperiences to life! He built a sleek, fast, and user-friendly website that perfectly reflects our brand. From design implementation to performance optimization, every detail was handled with excellence. I couldn’t be happier with the result!”
CEO, Sterling Experiences
“Working alongside Chidubem has been an amazing experience. He’s not just great at frontend development, but also incredibly supportive and collaborative. Whether it’s debugging tricky issues or brainstorming UX improvements, he always brings valuable insights to the table.”
Software Engineer, Yativo
“I’ve had the privilege of mentoring Chidubem and watching his growth as a frontend engineer. His technical skills, problem-solving ability, and dedication to excellence make him stand out. He’s more than ready for a full-time role, and any company that brings him on board will be gaining a valuable asset.”
Technology Executive
“What sets Chidubem apart, however, is his genuine enthusiasm and dedication to his work. He delivers high quality results and his effectiveness in meeting deadlines is impressive. He is a true asset to any team, and I highly recommend him for any opportunity.”
HR Specialist, Mavicon Investments
“It’s rare to find a frontend engineer who balances speed, quality, and maintainability so well. Chidubem’s code is clean, modular, and easy to scale. Our backend team had zero issues integrating his work, and performance metrics improved significantly.”
Developer Relations Manager, Moniepoint
+234 708 993 6232
chukwudubem7@gmail.com