Check/ Detect If Ionic View/ Page Reached Bottom Load Infinite Data

Like native Android apps, we sometimes need a view, where list items can be loaded after user reached the bottom of all loaded list items. This behavior is recommended if we have a long list to load and we don’t want the user to tap next every time to view next set of list items.

So we will do basically two things:

  1. How to Check If User Reached Bottom of Page/ View in Ionic App?

  2. How to Auto Load Infinite List of Records from API call in Single Ionic View?

 

Let’s begin…

Step 1) – In Our controller, we need to add an Ionic service $ionicScrollDelegate, then our controller will look something like this

 

Step 2) – Now we need to add some events in HTML which will call our Scroll function from the controller.

We will add on-scroll-complete=”checkScroll()” on our content HTML like below:

NOTE: I have used on-scroll-complete event Instead on on-scroll, becouse if we use on-scroll it will file on every pixel movement which can call api multiple times

 

Step 3) – In the controller, we will write logic to check if the view reached the bottom.

In above function $scope.loadNextRecords() will call more records and push to existing list.

Sometimes this we may want to call loadNext immediately when the user reaches the middle of the list, for that we can adjust values of  currentTop and maxTop accordingly.

Check Demo link, check console.log on link

Let me know if you have any feedback issues of better suggestion in comments below 🙂

 

4
Leave a Reply

avatar
2 Comment threads
2 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
3 Comment authors
Jolly.exeprabuadminprashanthraj Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
prashanthraj
Guest
prashanthraj

hi! i did what you have said but the ‘checkscroll ()’ function is not firing while scrolling ?

prabu
Guest
prabu

on-scroll-complete nor triggering after i reached bottom