javascript - How to check if all documents are loaded with Firebase.util pagination -
how can check if have stop calling loadmore()
function, because documents have been loaded database?
in example below i'm using ionic, it's same ng-infinite-scroll in angularjs apps.
this actual code:
html:
... <ion-infinite-scroll ng-if="!nomoreitemstoload" on-infinite="loadmore()" distance="5%"> </ion-infinite-scroll> </ion-content>
js controller:
$scope.loadmore = function(){ console.log('loading more docs...'); items.loadmore(); // calling .next() method inside items service if( !items.hasnext()) { $scope.nomoreitemstoload = true; } $scope.$broadcast('scroll.infinitescrollcomplete'); }
js items factory:
.factory('items', function (firebase_url, $firebasearray, $firebaseobject) { var itemsref = new firebase(firebase_url + 'items/'); var scrollref = new firebase.util.scroll(itemsref, 'name'); var self = { getallitems : function(){ ... }, loadmore: function(){ scrollref.scroll.next(4); }, hasnext: function(){ if(scrollref.scroll.hasnext()) { return true; } else { return false; } } } return self; }
do scroll.next
in timeout, example:
loadmore: function(){ $timeout(function() { scrollref.scroll.next(4); }); },
Comments
Post a Comment