Angularjs 滚动加载更多数据
来源: 阅读:1643 次 日期:2016-07-19 15:38:27
温馨提示: 小编为您整理了“Angularjs 滚动加载更多数据”,方便广大网友查阅!

下面的例子只是为了简单记录怎么使用angularjs来实现滚动加载数据,具体的还是需要具体看待:

Javascript部分的controller

app.controller('AnalysizerCtrl', ['$scope', '$timeout', '$window',

function ($scope, $timeout, $window) {

$scope.showData = false;

$scope.isLoadingPIG = false;

$scope.isLoadingUJ = false;

$scope.isLoadingBoxSummary = false;

$scope.LoadingData = function (index) {

$scope.showData = true;

var pigHeight = $(".analysisContainer")[1].children[1].scrollHeight;

var ujHeight = $(".analysisContainer")[1].children[2].scrollHeight;

var boxSummaryHeight = $(".analysisContainer")[1].children[3].scrollHeight;

if (index == 0) {

//$scope.reLoadData = true;

pigHeight = 0;

ujHeight = 0;

$scope.gridOptions.data = null;

}

var showSummaryBox = function () {

$scope.isLoadingBoxSummary = false;

}

var showUj = function () {

$scope.isLoadingUJ = false;

//$scope.isLoadingSummaryBox = true;

//$timeout(showSummaryBox, 1000);

}

var showPig = function () {

$scope.isLoadingPIG = false;

//$scope.isLoadingUJ = false;

//$timeout(showUj, 10000);

}

if (pigHeight == 0) {

$scope.isLoadingPIG = true;

$timeout(showPig, 1000);

} else if (ujHeight == 0) {

$scope.isLoadingUJ = true;

$timeout(showUj, 1000);

} else if (boxSummaryHeight == 0) {

$scope.isLoadingBoxSummary = true;

$timeout(showSummaryBox, 1000);

}

};

}]

).directive('whenScrollEnd', function () {

return function (scope, elm, attr) {

var pageWindow = $(this);

pageWindow.bind('scroll', function (et, ed, pb) {

var winScrollTop = pageWindow.scrollTop();

var winHeight = pageWindow.height();

var maxScrollHeight = $(".analysisContainer")[1].scrollHeight;

if ((winScrollTop + winHeight) > maxScrollHeight) {

scope.$apply(attr.whenScrollEnd);

}

});

}

});

下面是HTML部分:

<div class="analysisContainer" ng-show="showData" when-scroll-end="LoadingData()">

<div id="b" ng-show="isLoadingPIG" style="width: 100%; text-align: center; z-index: 1">

<h6 class="loading">

<img src="~/Content/Images/loading2.gif" />

Loading Win & Convert data...

</h6>

</div>

<div id="a" ng-show="!isLoadingPIG">

<img src="~/2016-03-16_152323.png" />

</div>

<div ng-show="!isLoadingUJ">

<img src="~/2016-03-16_153347.png" />

</div>

<div ng-show="!isLoadingBoxSummary">

<img src="~/2016-03-16_153404.png" />

</div>

</div>

重要的部分是指令(directive)和滚动时要加载数据的部分。

Angularjs 滚动加载更多数据的相关知识,小编就给大家介绍这么多,希望对大家有所帮助!

更多信息请查看网络编程
由于各方面情况的不断调整与变化, 提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 云南省教育厅备案号:云教ICP备0901021 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:
云南网警报警专用图标
Baidu
map