I am using ionic framework to create a basic Feed app. I got the refresher going but I'm having trouble with my ion-infinite-scroll.
Feed.html
<ion-content ng-controller="FeedController" >
<ion-refresher pulling-text="Pull to refresh.." on-refresh="get_feeds()" refreshing-text="Fetching ..." refreshing-icon="ion-loading-b">
</ion-refresher>
<ion-list>
<ion-item ng-repeat="question in questions">
<div class="item item-divider">
{{question.question}}
</div>
<div class="item" ng-bind-html="question.answer | trustHtml">
</div>
</ion-item>
</ion-list>
<ion-infinite-scroll
on-infinite="get_more()"
distance="1%">
</ion-infinite-scroll>
</ion-content>
Feed.js
(function(){
"use strict";
angular.module( 'app.controllers' ).controller( 'FeedController',
[ 'eTobb', 'Users', '$scope', '$timeout', function( eTobb, Users, $scope, $timeout) {
var pageIndex = 1;
$scope.questions = [];
$scope.get_feeds = function(pageIndex){
eTobb.get($scope.apiCall, { user_id: Users.id, page: 0 }, function(response) {
if ( response ){
$scope.questions = $scope.questions.concat(response);
console.log($scope.questions);
}
})
.finally(function(){
$scope.$broadcast('scroll.refreshComplete');
$scope.$broadcast('scroll.infiniteScrollComplete');
});
};
$scope.get_more = function(){
$scope.get_feeds(pageIndex);
pageIndex = pageIndex + 1;
console.log('why the hell am i being called?');
};
}
]);
})();
Issue
The method defined on the on-infinite property is called two times when the page loads and then is called normally (once) every time the bottom of the page is reached. Does anyone know why this happens?