I have two ion scroll tags. Inside each of these ion-scroll tags is a list. Each of these lists start with 10 items, and when a user reaches the bottom of a particular ion scroll it should load more. The problem I am facing is this is quite not working correctly. If I scroll through the first it scroll window and paginate through all the items it should say no more content. This does not happen though, instead if I scroll through the second scroll window then it will load more items in the first and second ion scroll window(which I don't want). Essentially I would like the two ion scrolls to be completely independent of each other. I would like each to load it's own content. I hope that made sense. Here is my codepen:
http://codepen.io/polska03/pen/jWKRwP
HTML:
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Ionic Pull to Refresh</title>
<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
</head>
<body ng-app="ionicApp" ng-controller="MyCtrl" class="background-places">
<ion-view>
<ion-content class="" scroll='false'>
<ion-scroll style="height:50%">
<ion-list>
<ion-item collection-repeat="list in _list">
<h2>Item</h2>
</ion-item>
</ion-list>
<button class="button button-full button-outline button-positive" ng-if="noMoreContent">
No more Content
</button>
<ion-infinite-scroll ng-if="canWeLoadMoreContent()" on-infinite="populateList()" distance="1%">
</ion-infinite-scroll>
</ion-scroll>
<hr>
<hr>
<ion-scroll style="height:50%">
<ion-list>
<ion-item collection-repeat="list2 in _list2">
<h2>Item</h2>
</ion-item>
</ion-list>
<button class="button button-full button-outline button-positive" ng-if="noMoreContent2">
No More Content
</button>
<ion-infinite-scroll ng-if="canWeLoadMoreContent2()" on-infinite="populateList2()" distance="1%">
</ion-infinite-scroll>
</ion-scroll>
</ion-content>
</ion-view>
</body>
</html>
Javascript:
angular.module('ionicApp', ['ionic'])
.controller('MyCtrl', function($scope) {
$scope._list = [];
$scope.populateList = function() {
for (var i = 0; i <= 9; i++) {
$scope._list.push({});
}
console.log($scope._list.length);
$scope.$broadcast('scroll.infiniteScrollComplete');
}
$scope.noMoreContent = false;
$scope.canWeLoadMoreContent = function() {
if($scope._list.length > 15) {
$scope.noMoreContent = true;
return false;
}else{
return true;
}
}
$scope.populateList();
$scope._list2 = [];
$scope.populateList2 = function() {
for (var i = 0; i <= 9; i++) {
$scope._list2.push({});
}
console.log($scope._list2.length);
$scope.$broadcast('scroll.infiniteScrollComplete');
}
$scope.noMoreContent2 = false;
$scope.canWeLoadMoreContent2 = function() {
if($scope._list2.length > 15) {
$scope.noMoreContent2 = true;
return false;
}else{
return true;
}
}
$scope.populateList2();
});
The issue comes from the 'require' ?^ionicScroll that is not resolved properly in the directive. Not sure why, as I'm not an AngularJS expert. That said, I found a workaround which is about inserting an extra div around the content tags, as in http://codepen.io/priand/pen/PzYbZG, if this helps someone.
<div>
<ion-content class="has-header col col-50">
<ion-list>
<ion-item ng-repeat="item in items"
item="item">
Item {{ item.id }}
</ion-item>
</ion-list>
<ion-infinite-scroll ng-if="!noMoreItemsAvailable" on-infinite="loadMore()" distance="10%"></ion-infinite-scroll>
</ion-content>
</div>
<div>
<ion-content class="has-header col col-offset-50 col-50">
<ion-list>
<ion-item ng-repeat="item in items2"
item="item">
Item {{ item.id }}
</ion-item>
</ion-list>
<ion-infinite-scroll ng-if="!noMoreItemsAvailable2" on-infinite="loadMore2()" distance="10%"></ion-infinite-scroll>
</ion-content>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With