×

Ionic Infinite Scroll

The infinite scroll permits you to perform an action when the user scrolls a particular content from the bottom or top of the page. When you display the large collection of data at once, then the infinite scroll is very useful.

You must require a way to display a large amount of data in a mobile application. In that case, the infinite scroll helps to display the content. For example, if you load the various items on the page, then you scroll the content and reach close to the bottom. The expression (ionInfinite) = “loadData($event)” set in the <ion-infinite-scroll> components are called when the user reaches close to the specified distance. When the expression has finished its all tasks, then it should call the complete() method on the infinite scroll instance.

You can use the <ion-infinite-scroll> component to create the infinite scroll in the ionic application. You can understand the ionic infinite scroll more clearly when you scroll the Twitter, Facebook, and Instagram news feed. The current page always loads the new news feeds on that current page, and you will see the loading spinner on the bottom of the view.

Ionic Infinite Scroll Content

The ion-infinite-scroll-content component is the child component of the <ion-infinite-scroll> component. It shows the infinite scroll spinner that looks good based on the platform, and it also changes the display based on the state of infinite scrolls. Infinite scroll provides the properties for scrolling, such as loadingSpinner and loadingText.

Note: The ion-infinite-scroll-content component is not supported in the ReactJS.

Example: This example explains how you can use the infinite scroll component in the ionic application.

Home.page.html

This file calls the event to show the infinite scroll content in the application. The [disabled] = “numTimesLeft <= 0” expression is used to stop the content scrolling. Here, you can also use the loading spinner and loading message, which shows the data when the method is called. You can use the loading spinner and loading text inside the <ion-infinite-scroll-content> component.

<ion-header>  
   <ion-toolbar color="primary">  
     <ion-title>Infinite Scroll Example</ion-title>  
   </ion-toolbar>  
 </ion-header>   
 <ion-content class="ion-padding" color="light">   
  <h1>Infinite Scroll</h1>
   <ion-list>  
     <ion-item *ngFor="let item of items"> {{item}} </ion-item>  
   </ion-list>  
   <ion-infinite-scroll threshold="110px" (ionInfinite)="loadData($event)" [disabled]="numTimesLeft <= 0">  
     <ion-infinite-scroll-content  
       loadingSpinner="circles"  
       loadingText="Loading Data.....">  
     </ion-infinite-scroll-content>  
   </ion-infinite-scroll>   
 </ion-content>   

Home.page.ts

In the Home.page.ts file, you can use the for-loop function to add the dummy items on a loading page. There are two methods used in this file. The loadData() method is called when the item list is reached at the bottom, and the complete() method is called to stop the loader, when the event is completed. Here, you can also set the setTimeout() method for loading the process to display the loading data.

import { Component} from
'@angular/core';  
 @Component({  
   selector: 'app-home',  
   templateUrl: 'home.page.html',  
   styleUrls: ['home.page.scss'],  
 })   
 export class HomePage {  
   items = [];  
   numTimesLeft = 4;  
   constructor() {   
     this.addMoreItems();  
   }  
   loadData(event) {  
     setTimeout(() => {  
       console.log('Done');  
       this.addMoreItems();   
       this.numTimesLeft -= 1;  
       event.target.complete();  
     }, 400);  
   }   
   addMoreItems() {  
     for (let i = 1; i < 12; i++) {  
       this.items.push(i);   
     }  
   }  
 }   

Output: After executing this code, you will get the output, as shown below:

Ionic Infinite Scroll

When you reached the bottom of the page, then it starts loading process, and it displays more data at the page when you scroll. The output shows below:

Ionic Infinite Scroll2

Related Topics

Ionic Infinite Scroll

The infinite scroll permits you to perform an action when the user scrolls a particular content from the bottom or top of the page. When you display the large collection of data...

3 minutes read.

Ionic Camera

Hybrid mobile applications can make very quickly, but sometimes it becomes a challenge to get the features that access the hardware such as GPS, storage, file storage, cameras, and networks. Cordova offers plugins...

4 minutes read.

Features of Ionic Framework

The Ionic Framework is based on the AngularJS framework that permits a programmer to use a combination of many other programming languages, like HTML5, CSS, and JavaScript. Some of the...

4 minutes read.

Ionic Toolbar

A toolbar is a general toolbar that can be used in an application such as a header, sub-header, footer, or even a sub-footer. Because the ion-toolbar is flexbox-dependent, no matter how many toolbars...

3 minutes read.

Ionic progress bar

The ionic progress bar element is a horizontal progress bar used to visualize the progression of operation and activity. You can use the <ion-progress-bar> component to create a progress bar in the ionic...

4 minutes read.

Ionic Splash Screen

The Apache Cordova plugin helps to displays and hides a splash screen during the application launch. The Ionic Splash Screen is similar to a home page on a website. The ionic splash...

2 minutes read.

Ionic Date Time

Ionic Date Time The DateTime component is used to display an interface that makes it simple for users to select dates and times. Tapping on <ion-datetime> will display a slider up from the...

4 minutes read.

Ionic Toggle

The toggle is the same as the HTML checkbox entry, but it looks different and easier to use on a touchscreen device. It is an input component that holds the boolean value. Toggle...

2 minutes read.

Ionic Input

Ionic Input Inputs are necessary to collect and process user inputs securely. To be easy for users to communicate, they must follow the process and communication guidelines for each platform. It is a...

3 minutes read.

Ionic Refresher

Refresher means updating the currently showing page so that the user can see the latest view. It is also known as re-loading in web technology. It provides a pull- to-refresh feature on a...

4 minutes read.

Ionic Editors

Editors are software programs that permit the users to create and edit the text files. In the development field, editors are usually used to create the source code editors that includes many specific...

3 minutes read.

Ionic Menu

The Ionic menu is the side-menu navigation that can be slide in from the side of the current view. By default, the menu slides in from the left side, but the side...

7 minutes read.

Ionic Geolocation

In today’s time, the mobile location plays an essential role in the mobile application. The Ionic Cordova geolocation plugin provides information about the location of the device, like as latitude and longitude. The...

5 minutes read.

Ionic Radio

Ionic Radio The radio button is the type of input component that has a Boolean value. The Ionic radio button has a different pattern on every platform, as well as other Ionic components....

2 minutes read.

Ionic Slides

The ionic slides component is the multi-section container. You can swipe or drag any segment between them. This contains any number of slides components. Slides help it easy to make galleries, tutorials, and...

2 minutes read.

Ionic Spinner

The ionic spinner component provides the various SVG (Scalable Vector Graphic) spinners. Ionic spinners are the visual indicators that display the app which is loading content or performing another process that the user...

5 minutes read.

Ionic Tabs

The ionic tabs mostly used for mobile navigation. It means that tabs are placed at the top of the display on android devices, while at the bottom on IOS. It does not provide...

2 minutes read.

Ionic vs React Native

Ionic Vs React Native Ionic and React Native are both common framework which is used to develop mobile applications. Here, you will know about the popular differences between the ionic and the React Native. Ionic Ionic...

3 minutes read.

Ionic framework Installation

Installation of Ionic Before proceeding with the ionic application, you'll need to install node.js and NPM (Node Package Manager), the code editor, and Ionic CLI. Installation of node.js and NPM These are the primary...

5 minutes read.

Ionic Popover

The Ionic popover is a small dialog box that displays at the top of the screen. It can be used for anything, but it is usually used for a button, an action,...

4 minutes read.