Description
HI, I'm working with the version of ionic "1.0.0-beta.12 Krypton Koala (09/10/2014)" and I have a problem with the infinite scroll.
the problem is that when I call the fetch () function in the service, it generates an infinite loop, as if the event "scroll.infiniteScrollComplete" would not be called.
I tried not to use the infiniteScroll and my data is well displayed. (http://codepen.io/calendee/pen/pzJLl)
I also tried to run various examples found here (airlines, etc.), but always with the same result, the fetch() function generates an infinite loop.
My code is:
HTML
<ion-view title="Users">
<ion-content class="padding" has-bouncing='true'>
<ion-refresher on-refresh="doRefresh()"
pulling-text="Rilascia per ricaricare..."
refreshing-text="Caricamento!"
refreshing-icon="ion-loading-c">
</ion-refresher>
<ion-list>
<ion-item ng-repeat="item in users"
class="item-thumbnail-left" href="#/tab/user/{{item.pk}}">
<h2>{{item.fields.nome}}</h2>
<h2>{{item.fields.descrizione | htmlToPlaintext}}</h2>
</ion-item>
</ion-list>
<ion-infinite-scroll icon="ion-loading-c" on-infinite="fetchUsers()"
distance="5%">
</ion-infinite-scroll>
</ion-content>
</ion-view>
Controller:
.controller('ListUsersCtrl', function ($scope, $q, $http, $timeout, DataService) {
$scope.limit = 5;
$scope.title = "Users";
$scope.MoreItemAvailable = true;
$scope.users = []
$scope.fetchUsers = function(){
DataService.fetchUsers().then(function(data){
$scope.users = data;
console.log($scope.users)
$scope.$broadcast('scroll.infiniteScrollComplete');
})
}
$scope.fetchUsers()
})
Service:
.factory('DataService', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {
var fetchUsers = function () {
var start = requestCounter * requestLimit;
var users = $http.get("data/users.json").success(function(data){
users = data
}).error(function(error){
console.log(error)
})
return users
}
}
return{
fetchUsers: fetchUsers
};
}
thank you