Today we are going to know about infinite/unlimited scrolling in AngularJS.
Infinite/unlimited scroll is while we scroll down our web page it’ll automatically load next paged data. Facebook has this type of feed loading.
Let’s Get Started
Let’s create a view with directive ‘when-scrolled’. AngularJS ‘when-scrolled’ directive is to implement infinite scrolling, which is supposed to detect the div scroll.
when-scrolled="loadData(1)"
Here ‘loadData(1)’ callback function will get called while div/page is scrolled. In this method we have passed parameter value ‘1’ to detect, is it default data load or scroll load call.
$scope.loadData = function (IsPaging) {}
This is where we passed the parameter in our ngController method.
Finally, the View:
- <div class="widget-content content_scroll" when-scrolled="loadData(1)">
- <table class="table table-striped table-bordered table-hover table-checkable datatable">
- <thead>
- <tr>
- <th>Office ID</th>
- <th>Office Code</th>
- <th>Office Name</th>
- <th>Is Active</th>
- <th>Create Date</th>
- <th>Create By</th>
- <th>Edit Date</th>
- <th>Edit By</th>
- <th>Status</th>
- </tr>
- </thead>
- <tbody>
- <trng-repeat="dataModel in ListOffice">
- <td>{{dataModel.OfficeID}}</td>
- <td>{{dataModel.OfficeCode}}</td>
- <td>{{dataModel.OfficeName}}</td>
- <td>{{dataModel.IsActive}}</td>
- <td>{{dataModel.CreateDate|date:"MM/dd/yyyy 'at' h:mma"}}</td>
- <td>{{dataModel.CreateBy}}</td>
- <td>{{dataModel.EditDate|date:"MM/dd/yyyy 'at' h:mma"}}</td>
- <td>{{dataModel.EditBy}}</td>
- <td>
- <span class="label label-warning">
- <a href="javascript:void(0);" class="bs-tooltip" title="Edit" ng-click="getOffice(dataModel)">
- <i class="icon-pencil"></i>
- </a>
- </span>
- <span class="label label-danger">
- <a href="javascript:void(0);" class="bs-tooltip" title="Delete" ng-click="deleteOffice(dataModel)">
- <i class="icon-trash"></i>
- </a>
- </span>
- </td>
- </tr>
- </tbody>
- </table>
- <div class="loadmore">
- <div ng-show="loaderMore" ng-class="result">
- <imgsrc="~/Areas/Crm/Content/img/ng-loader.gif" />{{LoadMessage}}
- </div>
- <div ng-show="scrollended" ng-class="result">
- {{LoadMessage}}
- </div>
- </div>
- </div>
The directive: This will detect the scroll position of page/div.
- .directive('whenScrolled', function()
- {
- return function(scope, elm, attr)
- {
- var raw = elm[0];
- elm.bind('scroll', function()
- {
- if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight)
- {
- scope.$apply(attr.whenScrolled);
- }
- });
- };
- })


Pete AppletonPosted Feb 4, 2016, 7:53 AM
Umm, sorry to burst your bubble but that code is truly horrible - it breaks all JS good practice and won't even lint. Missing spaces in variable declarations ("varinCallback"), UpperCased variables and properties, //commented out debugger lines, and line breaks before{ blocks } Personally, I'd be ashamed to have my name associated with that code and certainly wouldn't permit it through a code review.
Humayun Kabir MamunPosted Feb 3, 2016, 11:17 PM
Nice...
Pramod ThakurPosted Feb 2, 2016, 1:06 PM
Nice..
Shubham KumarPosted Feb 2, 2016, 1:08 AM
nice one keep share
Mohammed IbrahimPosted Feb 1, 2016, 2:11 PM
nice
Bhavik PatelPosted Feb 1, 2016, 8:59 AM
great share
Sibeesh VenuPosted Feb 1, 2016, 1:11 AM
Nice Share
Ankit BansalPosted Feb 1, 2016, 12:37 AM
nice one..
Debasis SahaPosted Jan 31, 2016, 11:23 PM
Good One..
Santhakumar MunuswamyPosted Jan 31, 2016, 12:35 PM
Thanks for nice article