【问题标题】:iScroll5 & Angularjs 1.2 not workingiScroll5 & Angularjs 1.2 不工作
【发布时间】:2014-05-06 08:53:17
【问题描述】:

附上

<script src="js/angular/angular.js"></script>    
<script src="js/lib/iscroll.js"></script>
<script src="js/lib/ng-iscroll.js"></script>

JS 文件

var App = angular.module('MyApp', [ 'ng-iscroll', ]);

App.controller('LoadUsers', ['$scope', function ($scope) {
    $.ajax({
        url: JSON URL HERE,
        type: 'GET',
        dataType: 'json',
        headers: {
            'Accept-Encoding': 'gzip'
        },
        crossDomain: true,
        timeout: 15000,
        success: function (data) {
            var nData = [];
            angular.forEach(data, function (value, key) {
                /* ############################ Scope ############################ */
                var nItem = {};
                nItem.fleetUser = value.name;
                nData.push(nItem);
            });

            $scope.fleet = nData;
            $scope.$apply();

        },
        error: function (data) {
            $scope.error = true;
            $scope.$apply();
        }
    });

}]);

HTML

<div ng-controller="LoadUsers">
    <div id="wrapper" ng-iscroll>
        <ons-list>
            <ons-list-item ng-show="error">Server Connection Error</ons-list-item>
            <ons-list-item class="topcoat-list__item__line-height" ng-repeat="item in fleet">{{item.fleetUser}}
                <br/>
            </ons-list-item>
        </ons-list>
    </div>
</div>

您好,我在将最新的 iScroll 实施到我的项目时遇到了麻烦。在我的移动设备上,列表没有显示,我得到的唯一错误是:

Uncaught TypeError: Cannot read property 'length' of undefined iscroll.js:1303
IScroll.goToPage iscroll.js:1303
IScroll._wheel iscroll.js:1084
IScroll.handleEvent

这是将 iSroll 实现为 Angular 重复的正确方法吗?啊,没有它,列表也能正常工作。

谢谢

【问题讨论】:

    标签: javascript angularjs iscroll


    【解决方案1】:

    更新

    你可以试试GitHub - @acido69的解决方案。它对我有用。

    <li ng-repeat="list in lists">
        <h3>{{list.text}}</h3>
        <p>{{list.done}} With Angular JS</p>
        {{ updateScroll($last) }}
    

    // in controller
    var Scroller = new iScroll('wrapper');
    $scope.lists = [{text:'', done:''}];
    $scope.updateScroll = function(isLast){
      if(isLast) Scroller.refresh()
    }
    

    See Example

    原始答案

    到目前为止,我认为你不能,因为在 iscroll4 中仍然存在关于 ng-repeat 的问题。 See ng-iscroll issue

    希望他们能尽快修复它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-01
      • 2017-05-12
      • 1970-01-01
      • 2013-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多