2013-12-23 33 views
0

我試圖實現一個無限的滾動指令。當頁面第一次加載並滾動時,我在控制檯上看到日誌。然而,在最初的滾動之後,它不再發生。就像它只做了一次。角度指令停止射擊

我哪裏錯了?

指令:

directives.directive('ngScrolled', function() { 
     return function(scope, elm, attr) { 
      var raw = elm[0]; 

      elm.bind('scroll', function() { 
       console.log('scroll direct'); 

       if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) { 
        scope.$apply(attr.ngScrolled); 
       } 
      }); 
     }; 
    }); 

HTML:

<div class="col-md-7 col-lg-7" ng-style="resultsHolder" ng-include="'partials/resultCell.html'" ng-scrolled="loadMore()"></div> 
+3

有沒有可能'div'實際上只滾動一次而其他滾動事件正在更高級別的對象中發生?小提琴會幫助! –

回答

1

由於NuclearGhost在評論中提到,它可能是滾動事件不會解僱你對指令的元素。

確保你有一個包裝器/容器元素的高度設置爲正確的溢出集。

這裏有一個fiddle有效的你的指示爲書面,它的工作原理。如果包裝div不存在,它將不起作用。

<body ng-app="app" ng-controller="main"> 
    <div class="scroller" infinite-scroll="more()"> 
     <div class="item" ng-repeat="item in items">{{item}}</div> 
    </div> 
</body>