3

I'm using ons-scroller to load data from some site using $http. But, the function I passed to on-scrolled is never called. Here is my code.

HTML

<ons-scroller infinite-scroll-enable="true" on-scrolled="loadMore()">
  <ons-list>
    <ons-list-item modifier="chevron" class="list-item-container" ng-repeat="post in posts">
        <ons-row>
          <ons-col width="95px">
            <div class="thumb-wrapper">
                <img src="{{post.thumbnail}}" class="thumbnail" alt="Blog image">   
            </div>
          </ons-col>
          <ons-col>
    <div class="name">
        {{post.title}}
    </div>
    <div class="location">
        {{post.description}}
    </div>
          </ons-col>

        </ons-row>
      </ons-list-item>
  </ons-list>
</ons-scroller>

AngularJS

var offset = 0;

$scope.posts = [];

$scope.loadMore = function(){
    if(offset == 0){
        $http({
            method: "GET",
            url: domain + "blog/list",
        })
        .success(function(data){
            $scope.posts = data.response.posts;
            offset++;
            $scope.loadMore();
        });
    }else{
        $http({
            method: "GET",
            url: domain + "blog/list",
            params: {
                offset: offset,
            }
        })
        .success(function(data){
            for(i = 0; i < data.response.posts.length; i++){
                $scope.posts.push(data.response.posts[i]);
            }
            offset++;
            if(data.response.posts.length == 0){
                return;
            }
            $scope.loadMore();
        });
    }
}
$scope.loadMore();

I'm calling loadMore(); manually in my controller.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Danish Jamil
  • 1,090
  • 11
  • 31
  • The directive is actually "infinit-scroll-enable", not "infinite". It should work if you use that. There is also an element called that can be used for large lists: http://onsen.io/reference/ons-lazy-repeat.html – Andreas Argelius Mar 16 '15 at 09:13
  • infinit-scroll-enable is also not working. Any other solution other than lazy-repeat? Because I find lazy-repeat complex. – Danish Jamil Mar 16 '15 at 09:29

0 Answers0