我试图使ngInfiniteScroll工作,但徒劳地-Plunker。滚动事件仅在页面加载时触发,此后似乎没有任何触发事件。任何人都可以阐明一下。
我尝试了各种组合,但都无效:
infinite-scroll='loadMore()' infinite-scroll-distance='2' infinite-scroll-container="'#list-wrapper'"
infinite-scroll='loadMore()' infinite-scroll-distance='2' infinite-scroll-parent
infinite-scroll='loadMore()' infinite-scroll-distance='2'
HTML:
<body ng-app="app" ng-controller="listController">
<div id="list-wrapper">
<div class="list" infinite-scroll='loadMore()'
infinite-scroll-distance='2'
infinite-scroll-container="'#list-wrapper'">
<div class="header">
</div>
<div class="list-table" >
<table class="table">
<tbody>
<tr ng-repeat="item in infiniteList">
<td style="width:100%">
<div>{{item}}</div>
</td>
</tr>
</tbody>
</table>
</div>
<div style='clear: both;'></div>
</div>
</div>
JS:
var app = angular.module("app", ['infinite-scroll']);
app.controller('listController', ['$scope','$http', function ($scope,$http) {
$scope.infiniteList = [];
$scope.incr = 1;
$scope.loadMore = function(){
console.log("scroll");
for(var i = 0; i< 30; i++){
$scope.infiniteList.push("Item " + $scope.incr);
$scope.incr +=1;
}
};
}]);
最佳答案
编辑:您正在使用ngInfinite Scroll的最新稳定版本,该版本没有-container和-parent方法,我已经用ngInfiniteScroll.js开发了插件,现在您可以在此处查看工作代码:
http://plnkr.co/edit/Bs9RYXhSAPhmQG5M6pyg?p=preview
老的:
因此,如果更改css并删除max-height,以便列表覆盖页面,则当用户滚动到页面上方时,您将看到infinitescroll正在工作。
#list-wrapper{
//max-height: 400px;
overflow-y: scroll;
margin-top: 20px;
border: solid 1px black;
}
http://plnkr.co/edit/aaUWnnKoH9kXGFx70U2J?p=preview
另请参阅:angularjs infinite scroll in a container