I'm currently working on implementing AngularJS Infinite Scroll without using jQuery. My goal is to display the first 3 data items when the page loads and then load the next 3 data items from a JSON array object as the user scrolls. The issue I am facing is that while I can successfully load the initial 3 data items, when scrolling, it repeats loading the first 3 items instead of showing the next set. Additionally, I want the scroll functionality to show the next set of data when scrolling down and the previous set when scrolling up (similar to a pagination concept).
Below is the array used to parse the data in the controller:
var app = angular.module('Demo', []);
app.controller('VerticleDemo', function($scope) {
$scope.items = [];
$scope.Arr = [{
"Select": "11",
"PhotoCount": "12"
}, {
"Select": "21",
"PhotoCount": "22"
}, {
"Select": "31",
"PhotoCount": "32"
}, {
"Select": "1",
"PhotoCount": "1"
}, {
"Select": "71",
"PhotoCount": "72"
}, {
"Select": "441",
"PhotoCount": "90"
}, ];
$scope.addItems = function() {
for (var i = 0; i < 3; i++) {
$scope.items.push($scope.Arr[i]);
}
};
$scope.addItems();
});
.scroll-loader {
background: #f7f7f7;
height: 90px;
border: 3px solid #d2d2d2;
margin-bottom: 20px;
overflow: auto;
padding: 10px 0;
border-radius: .5rem 0 0 .5rem;
}
.scroll-loader li {
list-style: none;
border-bottom: 1px solid #aaa;
padding: 5px;
margin-bottom: 3px;
}
I've been struggling with eliminating duplicate data and have tried various solutions without success. You can find my jsFiddle link below for reference: https://jsfiddle.net/sathishkti/96qhssfe/15/ Any help or guidance on resolving this issue would be greatly appreciated.