Angularjs 滾動加載更多數(shù)據(jù)
下面的例子只是為了簡單記錄怎么使用angularjs來實現(xiàn)滾動加載數(shù)據(jù),具體的還是需要具體看待:
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)和滾動時要加載數(shù)據(jù)的部分。
Angularjs 滾動加載更多數(shù)據(jù)的相關(guān)知識,小編就給大家介紹這么多,希望對大家有所幫助!
相關(guān)文章
AngularJS數(shù)據(jù)源的多種獲取方式匯總
在AngularJS中獲取數(shù)據(jù)源的方式有很多種,本文給大家整理幾種獲取數(shù)據(jù)源的方式,對angularjs獲取數(shù)據(jù)源的方式相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧2016-02-02
Angularjs中ng-repeat-start與ng-repeat-end的用法實例介紹
這篇文章主要給大家介紹了Angularjs中ng-repeat-start與ng-repeat-end的用法,文章開始先進(jìn)行了簡單的介紹,而后通過完整的實例代碼詳細(xì)給大家介紹這兩者的用法,有需要的朋友們可以參考借鑒,下面來一起看看吧。2016-12-12
AngularJs unit-testing(單元測試)詳解
本文主要介紹AngularJs unit-testing(單元測試)的內(nèi)容,這里整理了單元測試的知識,及示例代碼,有興趣的朋友可以參考下2016-09-09
Angular跨字段驗證器中如何直接調(diào)用其它獨立的驗證器
我們在開發(fā)的時候都會用到表單,那么驗證器就是必不可少的東西,這篇文章主要給大家介紹了關(guān)于在Angular跨字段驗證器中如何直接調(diào)用其它獨立的驗證器的相關(guān)資料,需要的朋友可以參考下2022-03-03
Angularjs的$http異步刪除數(shù)據(jù)詳解及實例
這篇文章主要介紹了Angularjs的$http異步刪除數(shù)據(jù)詳解及實例的相關(guān)資料,這里提供實現(xiàn)思路及實現(xiàn)具體的方法,需要的朋友可以參考下2017-07-07

