angularjs实现下拉加载更多

时间:2023-02-05 21:19:53

angularjs实现下拉加载更多数据,

我是通过指令来实现的,直接上代码





.directive("scroll",  ["$window", "$document",function ($window, $document) {
return function(scope, element) {
angular.element($window).bind("scroll", function() {
var pageYOffset = $window.pageYOffset;
var clientHeight = $document[0].documentElement.clientHeight;
var offsetHeight = $document[0].body.offsetHeight;
//当滚动到90%的时候去加载
if(pageYOffset+clientHeight>offsetHeight*0.9)
{

//scope.shopWorkCanLoad是否可加载,controller中定义
//scope.shopWorkOnLoad是否正在加载,controller中定义
if(scope.shopWorkCanLoad==true && scope.shopWorkOnLoad==false){
//加载数据,controller中定义
scope.loadShopWork();//
}
}
});
};
}]);

就这么多

用法我就不用再说了吧