3

I used infinite-scroll on a div which is as below

<div ng-app='myApp' ng-controller='DemoController'>
  <div id="scroll" infinite-scroll='reddit.nextPage()' 
  infinite-scroll-disabled='reddit.stopscript'   infinite-scroll-distance='2'   
    style="height:500px;overflow-y:scroll; border:solid 1px black">             

  <div ng-repeat='item in reddit.items'>
      <span>{{item.CourseId}}</span>
      <span>{{item.Name}}</span>
  </div>
<div ng-show='reddit.busy'>Loading data...</div>

and my controller code is

var myApp = angular.module('myApp', ['infinite-scroll']);

 myApp.controller('DemoController', function ($scope, Reddit) {
$scope.reddit = new Reddit();
});

 // Reddit constructor function to encapsulate HTTP and pagination logic
    myApp.factory('Reddit', function ($http) {
   var Reddit = function () {
    this.items = [];
    this.busy = false;
    this.after = '';
    this.counter = 30;
    this.index = 0;
    this.stopscript = false;
};

Reddit.prototype.nextPage = function () {
    if (this.busy) return;
    this.busy = true;

    var url = "http://byui.demo.emsicareercoach.com/packets/coursesearch/?Limit=" +         this.counter + "&Offset=" + this.index + "&Search=&x-ResponseType=json&x-Password=944c8e5971db726e0a516f3c6fa2eb922c5a79bb732975421b7f2bf52acce51f";
    $http.get(url).success(function (data) {

        if (data.Results.length == 0) {

            this.stopscript = true;
        }
        else {               
            this.items.push.apply(this.items, data.Results);
            this.index = this.index + this.counter;              
        }
        this.busy = false;
    }.bind(this));
};

return Reddit;

});

this is working fine when my browser is minimized but when my browser is maximized it is showing the first thirty records then it is not hitting that ajax call function again. i used infinite-scroll-distance='2' and even given height to my div but still it is not showing scroll on maximized web page hence not functioning.Plz help

2 Answers 2

2

You have to define the infinite-scroll-container, otherwise it will always check the distance to the bottom of the browser window.

Change the HTML to something like this:

<div id="scroll" infinite-scroll='reddit.nextPage()'
     infinite-scroll-container="'#scroll'"
     infinite-scroll-disabled='reddit.stopscript' 
     infinite-scroll-distance='2'   
     style="height:500px;overflow-y:scroll; border:solid 1px black">

Where '#scroll' is the ID of the div containing the scrollable content.

Check this plunker

Important notice: This feature is not included in the latest stable release (v1.0.0) and is only available in the lastest development (master) release.

Sign up to request clarification or add additional context in comments.

4 Comments

@shukshum was this helpful?
i did it but no achange happened i also used ng-scroll-paret as well but still no change .actually my infinitescroll js file donot contain any definition for these attributes .do i need to add some other ref..??
Which version of ng-infinite-scroll are you using? In my plunker I'm using v1.1.2, can you try with that one?
oh i was using 1.0.0 which is default provided on its web site
-1

A simple workaround might be to increase the number of results that you fetch with your AJAX call so that your browser scrolls.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.