我正在使用类似的代码this http://jsfiddle.net/vojtajina/U7Bz9/在 AngularJS 中创建无限滚动效果。我尝试通过移动可滚动容器的内容(在本例中为ul
) 到一个单独的 html 文件,然后使用 ng-view 加载内容。
完成此操作后scope.$apply(attr.whenScrolled);
没有任何影响。这loadMore()
方法根本就不再被调用。
将 ul-content 移动到单独的文件并动态加载后,我是否更改了范围?
更新:
这是代码:
App.directive('whenScrolled', function() {
return function(scope, element, attr) {
var raw = element[0];
// binding on element doesn't work so this is a temp fix
$(document).bind('scroll', function() {
var scrollPercentage = (($(window).scrollTop() + $(window).height()) / $(document).height()) * 100;
if(scrollPercentage > 75 && !scope.in_progress && !scope.is_reached_end)
{
console.log('test')
scope.$apply(attr.whenScrolled);
}
});
};
});
App.config(['$routeProvider', function($routeProvider){
$routeProvider.when('/', {
templateUrl: 'views/offers.html',
controller: 'OffersCntl'
});
}]);
风景:
<div class="tileContainer" ng-controller="OffersCntl">
<h2>Something very important :)</h2>
<div id="tiles" class="tiles" when-scrolled="loadMore()">
<div ng-view></div>
</div>
</div>
我有一个相当胖的控制器,我不想用它来污染帖子。它基本上有一个scope.load More方法。