2013-04-24 90 views
3

我正在嘗試使用角度指令實現水平iScroll。iScroll in angularjs指令

這是我的指令代碼。

link: function(scope, elem, attrs) { 
     scope.winWidth = window.innerWidth; 
     scope.iScrollWidth = scope.winWidth *8.5 +'px'; 
     jQuery(angular.element(attrs.thelist)).css({'width':scope.iScrollWidth}); 

     var k_videoScroll = new iScroll(angular.element(attrs.scrollwrap),{ 
      snap: true, 
      bounce: false, 
      checkDOMChanges: false, 
      momentum: false, 
      hScrollbar: false, 
      vScrollbar: false, 
      overflow: false 
     }); 

我有id爲我的HTML頁面相關的一個div標籤的attrs.scrollwrap

<div id="videolist" class="videoScrollWrap" options="#thelist" wrapper="#deal-wrap" scrollwrap="#videoReviewsWrap">  
    <div id="videoReviewsWrap"> 
     <ul id="thelist"> 
     <li id='deal-wrap' ng-repeat="video in videoList" videoList='video'></li> 
     </ul> 
    </div> 
</div> 

我堅持是「無法設置屬性‘’未定義的」溢出的問題。

TypeError: Cannot set property 'overflow' of undefined 
at Object.iScroll (http://localhost/swordfish/web/js/lib/iscroll.js:89:31) 
at setScroll (http://localhost/swordfish/web/js/directives/d-product-details.js:395:33) 
at link (http://localhost/swordfish/web/js/directives/d-product-details.js:405:13) 
at o (http://localhost/swordfish/web/js/lib/angular/angular.min.js:42:187) 
at e (http://localhost/swordfish/web/js/lib/angular/angular.min.js:38:28) 
at http://localhost/swordfish/web/js/lib/angular/angular.min.js:37:118 
at <error: illegal access> 
at Object.e.$broadcast (http://localhost/swordfish/web/js/lib/angular/angular.min.js:88:517) 
at http://localhost/swordfish/web/js/lib/angular/angular.min.js:81:85 
at i (http://localhost/swordfish/web/js/lib/angular/angular.min.js:76:207) <div id="videolist" class="videoScrollWrap ng-isolate-scope ng-scope" options="#thelist" wrapper="#deal-wrap" scrollwrap="#videoReviewsWrap"> angular.min.js:60 

(匿名函數)

可能是什麼問題?看來定義新的iScroll的語法是不正確的。什麼是正確的方法來做到這一點?

在此先感謝!

+0

你可以發表評論作爲答案,這樣的問題將不會出現在未解答的問題列表,並變得更有助於他人?:) – 2013-04-27 20:36:52

回答

1

我想出了這個問題。這是因爲當我嘗試獲取(attrs.scrollwrap)時,它實際上是重新調整對象。但iScroll庫試圖直接獲取對象子元素,並設置該對象的style屬性。一旦我嘗試使用(attrs.scrollwrap [0])訪問div元素,問題就解決了。