我正在尝试使用无限滚动来延迟加载图像。当它被调用时,我收到以下错误:
TypeError:undefined不是函数 在处理程序(http://onfilm.us/ng-infinite-scroll.js:31:34)
这是我到目前为止的一个非常淡化的外观。
function tagsController($scope) {
$scope.handleClick = function(tags) {
// Parse Tags
$scope.finished_tags = parsed_data;
};
$scope.$emit( 'handleEmit', { tags = $scope.finished_tags; });
};
function imagesController($scope,$http) {
var rows_per = 5;
$scope.$on('handleBroadcast', function(event, args) {
// Sort the images here, put them in matrix
// Example: matrix[row_number] = { picture1, picture2, picture3 }
$scope.data = matrix;
$scope.loadMore();
};
$scope.loadMore() = function() {
var last = $scope.images.length;
for ( var i = 0; i < rows_per; i++ ) {
$scope.images[last + i] = new Array();
$scope.images[last + i] = $scope.data[last + i].slice( 0 );
}
}
}
粗略的想法是页面第一次加载(没有标签)并从PHP脚本中获取图像。他们都是。它们被存储,并调用loadMore(),它将使用5行图像填充$ scope.images。确实如此,它们已被加载。
该脚本中的行正在访问$ window.height和$ window.scrollup。我仍然是非常绿色的Javascript,所以如果我做了一些可怕的错误,请随意骂我。
这是我正在测试的破碎版本: http://onfilm.us/test.html
这是在实现延迟加载之前的版本,如果查看标记的工作方式将有所帮助。我不认为这是问题所在。
http://onfilm.us/image_index.html
编辑:我认为这是一个带有ng-infinite-scroll.js脚本的问题。错误在第31行(版本1.0.0)。它告诉我: TypeError:undefined不是函数 它显然不喜欢$ window。
我的JS Kung Fu并没有真正说明原因。你可以从这里的简单演示中看到文字复制/粘贴作业(有错误)onfilm.us/scroll2.html
答案 0 :(得分:1)
通过引用您的网站,首次出现您的HTML标记不合适。您应该将无限滚动移动到ng-repeat指令的父级,以便它不会对生成的每一行进行重叠调用。请访问http://binarymuse.github.io/ngInfiniteScroll/demo_basic.html