Hi,
i’m trying to get my infinite scroll to work. How would i do this?
I’d like my application to load 5 json messages in to start with and then when the user scrolls downwards it would continue to load more messages.
What i’ve got at the moment is a pull to refresh which loads details from a Json webpage. I’d like it to only load the newest messages first but when it scrolls downwards it would load the other messages. Hope that make sense.
Here’s my code:
HTML
<ion-refresher
pulling-text="Pull to refresh..."
on-refresh="doRefresh()">
</ion-refresher>
<ion-list>
<ion-item ng-repeat="data in data">
<div class="list card">
<div class="item item-divider">{{data.announcement_name}} - {{data.date}}</div>
<div class="item item-body">
<div>
{{data.message}}
</div>
</div>
</div>
</ion-item>
</ion-list>
<ion-infinite-scroll></ion-infinite-scroll>
</ion-content>
Javascript controller
angular.module('starter.controllers', [])
.controller('announcementsCtrl', function($scope, $http) {
$scope.data = [];
$scope.doRefresh = function () {
$http.get('http://wikicode.co.uk/announcement.json')
.success(function (data) {
$scope.data = data;
})
.finally(function () {
$scope.$broadcast('scroll.refreshComplete');
});
}
$scope.loadMore = function() {
console.log('Loading more!');
$scope.$broadcast('scroll.infiniteScrollComplete');
$scope.$broadcast('scroll.resize');
$scope.$broadcast('scroll.resize')
}, 1000;
})
If someone could help me or point me in the right direction that would be brilliant!