Code Monkey home page Code Monkey logo

Comments (5)

zoehneto avatar zoehneto commented on August 16, 2024 4

Based on your example this should work:

export class App implements OnInit{
  _contactsTotal:any; // get 500 data from server
  _contactsToRepeatInView:any;
  _waitData: boolean; //no ajax call if we are already waiting one

  constructor(private _contactService: ContactService) {}

  ngOnInit():any {
    this._contactsToRepeatInView = []
    this._waitData = false;

    this._contactService.getImages().map(res => res.json()).subscribe(data => {
      this._contactsTotal = data;
      this._contactsToRepeatInView = this._contactsTotal.splice(0,100); // show only 100 data from server response
    });
  }

  onScrollDown () {
    this._contactsToRepeatInView = this._contactsToRepeatInView.concat(this._contactsTotal.splice(0,100)) // when scrollDown concat() 100 additional data to actual view, from this._contactsTotal

    if(this._contactsTotal.length === 0){ //when this._contactsTotal equal 0 we do another ajax call and so the same stuff
      if(this._waitData === false){
        this._waitData = true;
        this._contactService.getImages().map(res => res.json()).subscribe(data => {
          this._contactsTotal = data
          this._contactsToRepeatInView = this._contactsToRepeatInView.concat(this._contactsTotal.splice(0,100))
          this._waitData = false;
        });
      }
    }
  }
}

from ngx-infinite-scroll.

zoehneto avatar zoehneto commented on August 16, 2024 1

That's because you always set _waitData to true before checking it.

from ngx-infinite-scroll.

orizens avatar orizens commented on August 16, 2024

hi @istiti
the purpose of this directive is to invoke the handler every time it scrolls after the specified "distance".
other specific logics should be resolved inside the component that's using it.

from ngx-infinite-scroll.

elvisbegovic avatar elvisbegovic commented on August 16, 2024

Could you please check my code I tried to implement something into component, with this._waitData properties but event with this solution I have more than one http call, I do not understand

from ngx-infinite-scroll.

elvisbegovic avatar elvisbegovic commented on August 16, 2024

do you have better implementation ? even pseudo-code :) what is the best way to implement this in onScrollDown() method

from ngx-infinite-scroll.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.