1
我有一堆产品,并且正在使用无限滚动来显示它们。它通常工作得很好,如果我不改变数组值。不过,我有不同类型的产品,并且有一个过滤器可以更改Firebase数据库端点并将新值加载到数组中。ngInfiniteScroll在更改源数组时不显示任何东西
来回改变会以某种方式使所有的产品消失。尽管如此,我确实看到从控制台添加到阵列的产品。
代码:
(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;
}
})();
前端代码:
<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>
从CONSOL数据库终点变化
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;
}
火力地堡数据服务代码
示例代码e,我看到以下内容:
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
任何想法这里发生了什么?
@Frank van Puffelen:好像我需要做一个$ digest或$ apply。有什么建议么 ? – Ahsan
你可以发布你的视图代码吗?我想看看你如何关联vm.products。 –