Pull To Refresh - Only New Items


#1

Hello,

I am developing an app using ionic 1 that brings JSON object with a list of items. Now, I want to understand how does “Pull To Refresh” work?

I want when the user calls pull to refresh, to bring ONLY the new items from the server rather than reloading everything. Does this require to be implemented in the Server or it is client side?

thanks,


#2

The general idea would be:
Store a last fetched timestamp, and pass that with the request to the server.
On the server side, check for any created after that timestamp.
Once you have your return, update the timestamp.

Though, be aware that the backend will treat timestamps in seconds, while the client treats it in milliseconds.

$scope.doRefresh = function() { $http.get('http://www.backend.com/getnewitems?timestamp='+$scope.lastUpdate) .success(function(newItems) { $scope.items = newItems; $scope.lastUpdate = Date.now(); }) .finally(function() { // Stop the ion-refresher from spinning $scope.$broadcast('scroll.refreshComplete'); }); };