6
I’m having a bit of trouble creating an infinite scroll in Angularjs from a JSON file generated on an external site. What I need is for the infinite scroll to be called when the variable item posts
is equal to 10, calling again my function, incrementing +1 in the URL, changing the page. Follow the code:
$scope.posts = [];
$scope.doRefresh = function(){
JsonNews.getBlogs($scope);
$scope.$broadcast('scroll.refreshComplete');
}
$page = 0;
function JsonNews($http, $log){
$page++;
$urlInfinite = "http://plantaojti.com.br/noticias/page/"+ $page +"/?feed=json&callback=JSON_CALLBACK";
this.getBlogs = function($scope){
$http.jsonp($urlInfinite).success(function(data){
$scope.posts = data;
for (var i = 0; i < $scope.posts.length; i++) {
this.posts.push(posts[i].data);
}
AppCtrl.$scope.doRefresh($scope);
});
}
}
In HTML:
<div infinite-scroll='JsonNews()' inite-scroll-distance='1'>
<ion-item data-ng-repeat="item in posts | filter: query" class="item-thumbnail-left item-text-wrap item-icon-right" href="window.open('{{item.permalink}}', '_system', 'location=yes'">
<img class="thumb-noticia" data-ng-src="{{item.thumbnail}}">
<h2> {{item.title}} </h2>
<p>{{item.excerpt | limitTo: 100}}...</p>
</ion-item>
</div>
I have long used a plugin bait to browse a list in
javascript
. It wasn’t an infinite scroll, but I’ve been watching and they even have a demo to an infinite. I don’t know if you can adapt it toangularJS
– msm.oliveira
After much trying to do, I discovered the ng-Infinite-scroll, that completely solved my problem.
– airton
I left a solution that I use right below, I hope you like it.
– Renan Degrandi
Possible duplicate of Load list by parts using Angularjs
– celsomtrindade