Skip to content

Commit

Permalink
Implementing pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
praneethkumarpidugu committed Jun 25, 2016
1 parent 2c93783 commit e8437d9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion section6/lesson1/index.html
Expand Up @@ -52,7 +52,7 @@

</form >

<table class="table table-bordered" infinite-scroll="loadMore()" infinite-scroll-distance="3">
<table class="table table-bordered" infinite-scroll="loadMore()" infinite-scroll-distance="1">

<tr >
<th >#</th >
Expand Down
31 changes: 25 additions & 6 deletions section6/lesson1/main.js
Expand Up @@ -25,6 +25,7 @@ app.controller('PersonListController', function ($scope, ContactService) {

$scope.loadMore = function () {
console.log("Load More!!!");
$scope.contacts.loadMore();
};

$scope.sensitiveSearch = function (person) {
Expand All @@ -49,12 +50,30 @@ app.service('ContactService', function (Contact) {
'selectedPerson': null,
'persons': [],
'loadContacts': function () {
Contact.get(function (data) {
console.log(data);
angular.forEach(data.results, function (person) {
self.persons.push(new Contact(person));
})
});
if (self.hasMore && !self.isLoading) {
self.isLoading = true;
var params = {
'page': self.page
};
Contact.get(params, function (data) {
console.log(data);
angular.forEach(data.results, function (person) {
self.persons.push(new Contact(person));
});
if (!data.next) {
self.hasMore = false;
}
self.isLoading = false;
});
}


},
'loadMore': function () {
if (self.hasMore && !self.isLoading) {
self.page += 1;
self.loadContacts();
}
}

};
Expand Down

0 comments on commit e8437d9

Please sign in to comment.