我正在使用类似this的代码在AngularJS中创建无限滚动效果。我试图通过将可滚动容器的内容(在这种情况下为ul
)重构为一个单独的html文件来重构一些代码,然后使用ng-view来加载内容。当在ng-view上滚动时无尽滚动在AngularJS中不起作用
完成此操作后,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>
我有一个相当脂肪控制器,这是我不想polute与职。它基本上有一个scope.loadMore方法。
请张贴代码调试 – rajkamal 2013-05-08 22:36:23
现在完成了。 – Dofs 2013-05-09 06:42:43