How to reload/refresh with infinite-scroll

@marq Sturm
Sun, 10 Jul 2016 08:28:10 +0000
ionic

@marq wrote:

i started on friday for the first time with the ionic framework to create my own small newsreader app for my blog. Im also a complete beginner on angular.

So here is my problem, I want to have a reload function.

My app should clear all data by using the reload function and grab the feed again. Event that works, but it shows me only the first 5 news (limit of my api/per page) and ignores completly the loadMore function.

factory

.factory('newsDataService', function($http) {
return {
  GetPosts: function(page) {
    return $http.get("http://newsapi.domain.tdl/");
  },
  GetMorePosts: function(page) {
    return $http.get("http://newsapi.domain.tdl/?page=" + page);
  }
  };
  })

controller

.controller('NewsCtrl', function($scope, newsDataService) {
$scope.page = 1;
$scope.noMoreItemsAvailable = false;

newsDataService.GetPosts().then(function(items){
  $scope.items = [];
  $scope.items = items.data.response;
});

$scope.doRefresh = function() {
  console.log('reload');
    newsDataService.GetPosts().then(function(items){
      console.log(items);
         $scope.items = items.data.response ;

         $scope.noMoreItemsAvailable = false;
         $scope.$broadcast('scroll.refreshComplete');
      })
  };

  $scope.loadMore = function(argument) {
    $scope.page++;
    newsDataService.GetMorePosts($scope.page).then(function(items){
          if (items.data.response) {
          $scope.items = $scope.items.concat(items.data.response);
            $scope.noMoreItemsAvailable = false;
          } else {
            $scope.noMoreItemsAvailable = true;
          }
      }).finally(function() {
        $scope.$broadcast("scroll.infiniteScrollComplete");
        });
  };
})

template

<ion-view view-title="News">
<ion-content>
<ion-refresher on-refresh="doRefresh()"></ion-refresher>


{{news.headline}}



  <ion-infinite-scroll ng-if="!noMoreItemsAvailable" on-infinite="loadMore()" distance="1%"></ion-infinite-scroll>
  </ion-content>
  </ion-view>

How can I resolve this?