I have a bunch of products and am using infinite scroll to display them. It generally works very well if I dont change the array values. However, I have different types of products and have a filter that changes the firebase database endpoints and loads the new values to the array.
Changing back and forth will somehow make all the products disappear. Even though, I do see the products being added to the array from console.
Code:
Sample code for database end point change
function getProductByTag(tag) {
if(lastSelection === tag && allproducts) {
console.log('do nothing, we are good');
} else if (lastSelection != tag) {
lastSelection = tag;
baseRef = firebaseDataService.root.child('products_' + tag.toLowerCase());
scrollRef = new firebase.util.Scroll(baseRef, '$key');
scrollRef.on('child_added', function(snap) {
console.log('added child', snap.key);
});
scrollRef.scroll.next(5);
allproducts = $firebaseArray(scrollRef);
// store the scroll namespace on the array for easy ref
allproducts.scroll = scrollRef.scroll;
} else {
console.log('We shouldnt be here');
}
return allproducts;
}
Firebase Data Service code:
(function () {
'use strict';
angular
.module('app.core')
.factory('firebaseDataService', firebaseDataService);
function firebaseDataService() {
var root = firebase.database().ref();
var service = {
root : root,
users : root.child('users')
};
return service;
}
})();
Front end code:
<div infinite-scroll="vm.products.scroll.next(10)" infinite-scroll-distance="1">
<div class="floating-box" ng-repeat="product in vm.products" ng-if="product.visibility">
<!--some code-->
</div>
</div>
From the console, I do see the following:
product.service.js:60 added child -KRe4D4pi5uDncBQyeLN
product.service.js:60 added child -KRe4OFAi3eYJEWGjMDv
product.service.js:60 added child -KRe5-PrzaaBr5YzzlMA
product.service.js:60 added child -KXlZL8bBzOjZ02DpCzW
etc
Any idea whats going on here ?