iScroll in angularjs指令

时间:2013-04-24 20:57:05

标签: angularjs overflow undefined angularjs-directive iscroll

我正在尝试使用angular指令实现水平iScroll。

这是我的指令代码。

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
        });

我的html页面中有一个div标签,其id与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的语法不正确。这样做的正确方法是什么?

提前致谢!

1 个答案:

答案 0 :(得分:1)

我想出了这个问题。这是因为当我试图获得(attrs.scrollwrap)它实际上是重新调整对象。但iScroll库试图直接获取对象子元素,并设置该对象的style属性。一旦我尝试使用(attrs.scrollwrap [0])访问div元素,问题就解决了。