Last active
February 24, 2022 06:51
-
-
Save katowulf/54fa9a1e713b61672f53 to your computer and use it in GitHub Desktop.
Simple paginate example in AngularFire with Firebase.util (http://firebase.github.io/firebase-util/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('app', ['firebase']); | |
app.controller('ctrl', function($scope, $pageArray) { | |
$scope.pageItems = $pageArray(ref, 'number'); | |
}); | |
app.factory('$pageArray', function($firebaseArray) { | |
return function(ref, field) { | |
// create a Paginate reference | |
var pageRef = new Firebase.util.Paginate(ref, field, {maxCacheSize: 250}); | |
// generate a synchronized array using the special page ref | |
var list = $firebaseArray(pageRef); | |
// store the "page" scope on the synchronized array for easy access | |
list.page = pageRef.page; | |
// when the page count loads, update local scope vars | |
pageRef.page.onPageCount(function(currentPageCount, couldHaveMore) { | |
list.pageCount = currentPageCount; | |
list.couldHaveMore = couldHaveMore; | |
}); | |
// when the current page is changed, update local scope vars | |
pageRef.page.onPageChange(function(currentPageNumber) { | |
list.currentPageNumber = currentPageNumber; | |
}); | |
// load the first page | |
pageRef.page.next(); | |
return list; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body ng-app="app" ng-controller="ctrl"> | |
<h4>Showing: Page {{ pageItems.currentPageNumber }} of {{ pageItems.pageCount }}<span ng-show="pageItems.couldHaveMore"> or more</span></h4> | |
<ul> | |
<li ng-repeat="item in scrollItems">{{item.$id}}: {{item.string}}</li> | |
</ul> | |
<p> | |
<button class="btn btn-primary" | |
ng-click="pageItems.page.setPage(1)" | |
ng-disabled="pageItems.currentPageNumber < 2"> | |
<i class="glyphicon glyphicon-fast-backward"></i> | |
</button> | |
<button class="btn btn-primary" | |
ng-click="pageItems.page.prev()" | |
ng-disabled="!pageItems.page.hasPrev()"> | |
<i class="glyphicon glyphicon-backward"></i> | |
</button> | |
<button class="btn btn-primary" | |
ng-click="pageItems.page.next()" | |
ng-disabled="!pageItems.page.hasNext()"> | |
<i class="glyphicon glyphicon-forward"></i> | |
</button> | |
<button class="btn btn-primary" | |
ng-click="pageItems.page.setPage(pageItems.pageCount)" | |
ng-disabled="!pageItems.page.hasNext() || pageItems.currentPageNumber >= pageItems.pageCount"> | |
<i class="glyphicon glyphicon-fast-forward"></i> | |
</button> | |
</p> | |
</body> |
Hi what is the field option in
var pageRef = new Firebase.util.Paginate(ref, field, {maxCacheSize: 250});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@prashant you can follow link