Hi, i suggest:
// CONTROLLERS
.controller('CarsCtrl', function($scope, $timeout, CarsFactory) {
$scope.cars = [];
$scope.currentPage = 0;
// Load More
$scope.loadMore = function (){
CarsFactory.getCars($scope.currentPage).then(function (response){
$scope.noMoreItemsAvailable = false;
if(response.data){
$scope.cars = $scope.cars.concat(response.data);
//console.log("length: "+$scope.cars.length+', page: '+$scope.currentPage);
$scope.noMoreItemsAvailable = true; // enable loadMore()
$scope.currentPage += 1;
$scope.$broadcast('scroll.infiniteScrollComplete');
}
// response.data = ""
});
};
$scope.loadMore();
// refefresh
$scope.doRefresh = function() {
$timeout(function () {
$scope.loadMore();
$scope.$broadcast('scroll.refreshComplete');
}, 1000);
};
})
// SERVICES
.factory('CarsFactory', function($http) {
var cars = [];
return {
getCars: function(page){
return $http.get('http://yourserver.com?page='+page).then(function(response){
cars = response; // return response.data;
return cars;
});
}
// ...
};
});
// EX: codeigniter
$per_page = (int)$this->input->get('page');
//$offset = $this->config->item('per_page');
$offset = 12;
$per_page = $per_page * $offset;
$products = $this->ads->get_ads($offset, $per_page);
if($products)
{
$ads = array();
foreach ($products as $k=>$v)
{
$ads[$k]['id'] = $v->id;
$ads[$k]['ad_headline'] = $v->ad_headline";
$ads[$k]['ad_text'] = $v->ad_text";
$ads[$k]['category'] = $v->category;
$ads[$k]['cateid'] = $v->cateid;
}
}else {
$ads = "";
}
$this->load->view('ajax_output',array('data'=>$ads));