Skip to content

Commit

Permalink
server side sorting and searching
Browse files Browse the repository at this point in the history
  • Loading branch information
praneethkumarpidugu committed Jul 6, 2016
1 parent 05c49a4 commit f35051a
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions section6/lesson1/main.js
Expand Up @@ -29,7 +29,14 @@ app.controller('PersonListController', function ($scope, ContactService) {
};

$scope.$watch('search', function(newVal, oldVal) {
console.log(newVal);
if (angular.isDefined(newVal)) {
$scope.contacts.doSearch(newVal);
}
})
$scope.$watch('order', function(newVal, oldVal) {
if (angular.isDefined(newVal)) {
$scope.contacts.doOrder(newVal);
}
})

});
Expand All @@ -45,11 +52,28 @@ app.service('ContactService', function (Contact) {
'isLoading': false,
'selectedPerson': null,
'persons': [],
'search': null,
'doSearch': function (search) {
self.hasMore = true;
self.page = 1;
self.persons = [];
self.search = search;
self.loadContacts();
},
'doOrder': function (order) {
self.hasMore = true;
self.page = 1;
self.persons = [];
self.ordering = order;
self.loadContacts();
},
'loadContacts': function () {
if (self.hasMore && !self.isLoading) {
self.isLoading = true;
var params = {
'page': self.page
'page': self.page,
'search': self.search,
'ordering': self.ordering
};
Contact.get(params, function (data) {
console.log(data);
Expand Down

0 comments on commit f35051a

Please sign in to comment.