Angular js - On scroll up load more data

橙三吉。 提交于 2019-12-07 19:04:44

问题


I have developed a chatting system like Facebook. Now I want to do load earlier messages. Can anyone help me to do the functionality like when I scroll up it should load earlier messages same like Facebook.


回答1:


You may want to take a look at ngInfiniteScroll. With this module, it is very easy to implement what you want. Here is an example:

<div ng-app='myApp' ng-controller='DemoController'>
  <div infinite-scroll='loadMore()' infinite-scroll-distance='2'>
    <img ng-repeat='image in images' ng-src='http://placehold.it/225x250&text={{image}}'>
  </div>
</div>

var myApp = angular.module('myApp', ['infinite-scroll']);
myApp.controller('DemoController', function($scope) {
  $scope.images = [1, 2, 3, 4, 5, 6, 7, 8];

  $scope.loadMore = function() {
    var last = $scope.images[$scope.images.length - 1];
    for(var i = 1; i <= 8; i++) {
      $scope.images.push(last + i);
    }
  };
});

If you are using Bower, you can install if with bower install ngInfiniteScroll.



来源:https://stackoverflow.com/questions/32687871/angular-js-on-scroll-up-load-more-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!