×

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 Actionsheet

Ionic Actionsheet The Action sheet is a dialog box that displays a group of options. It is shown on the top of the application content and must be dismissed manually before the user can resume...

3 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 List

Ionic List The ionic list is created of several rows of items that can contain text, buttons, thumbnails, keys, icons, and more. Lists are one of the essential components in any web or...

4 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 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 vs Apache Cordova

Ionic Vs Apache Cordova Ionic and Cordova are two popular technology going on in the market for mobile application development. The combination of these two technologies creates a development platform that is known as...

3 minutes read.

Ionic Colors

Ionic Colors Before we start with the actual elements available in the Ionic frame, let's understand a little bit how Ionic uses colors for different elements. Ionic Color Classes Ionic framework is a set of nine predefined...

3 minutes read.

Ionic Modal

Ionic modal is displayed as a temporary UI that slides into the screen. The ionic modal is a dialog box that is displayed at the top of the app’s content, and it...

5 minutes read.

Difference between Ionic 4 and Ionic 3

The ionic framework is an open-source platform that is used to develop mobile applications. It is also used to build android applications, desktop applications, iOS, and web applications using web technologies like HTML,...

5 minutes read.

Ionic Grid

The Ionic grid is a very powerful mobile-first flexbox system for building the custom layouts. It is a CSS feature supported by all devices that ionic supports. The Ionic grid is composed of...

11 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 Contents

Ionic Contents The content component provides an easy-to-use content area with some useful ways to control the scrollable region. There should be only one content in one view. Content, along with several other Ionic...

2 minutes read.

Ionic-fab Button

Ionic-fab Button The Ionic FABs (Floating Action Buttons) are standard material design compounds. It is a container element that contains one or more fab buttons. They are required to be placed in a fixed position,...

2 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 Range

The Range slider lets users choose from a range of values by moving the slider knob. You can accept two knobs, but by default, one-knob controls the range value. Range labels You can put down on...

2 minutes read.

Ionic Checkbox

Ionic Checkbox Ionic Checkbox is nearly the same as a toggle. It can be placed in an ionic element or used as a separate checkbox. It is designed differently for every platform, such...

2 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 Reorder

The Ionic offers the <ion-reorder> component to reordering features. Ionic reorder component adds the Drag and Drop feature to list items, in which the user can change the order of the items. Reorder...

3 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 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.