简体   繁体   中英

iScroll5 & Angularjs 1.2 not working

Attached

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

JS File

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>

Hi I have a trouble with implementing the lates iScroll into my project. On my mobile device the list is not showing and the only error I'm getting is:

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

Is this correct way of implementing iSroll into Angular repeat? Ah the list works fine without it.

Thanks

UPDATE

You can try the solution of GitHub - @acido69 . It worked for me.

<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

ORIGINAL ANSWER

As of now, I think you can't because there's still an issue in iscroll4 about ng-repeat. See ng-iscroll issue

Hope that they can fix it soon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM