scrollDown called many times (expected only 1)
See original GitHub issueHi, first thx to adapt infinite-scroll to angular2, my problem is when I scroll down, the onScrollDown() function is called more than one time, I want to call it only once see my code, is something strange?:
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
this._waitData = true; //this is problem
if(this._waitData === true){ //this is problem
this._contactService.getImages().map(res => res.json()).subscribe(data => {
this._waitData == false; //this is problem
this._contactsTotal = data
this._contactsToRepeatInView = this._contactsToRepeatInView.concat(this._contactsTotal.splice(0,100))
});
}
}
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
javascript - Scroll Function Firing Multiple Times Instead of Once
The scroll event (as well as the resize event) fire multiple times as a user does this. To help this, the best practice...
Read more >module "scroll-down" handler is being called multiple times
Expected behavior: The scroll-down handler should only be called once, like before. If the new behaviour is required, it should be configurable, ...
Read more >Automatic scrolling, only if a user already scrolled the bottom ...
In chat windows or similar growing lists, users often expect, that a page automatically scrolls to the latest item.
Read more >Scrolling - The Modern JavaScript Tutorial
The scroll event allows reacting to a page or element scrolling. There are quite a few good things we can do here. For...
Read more >SingleChildScrollView class - widgets - Flutter - Dart API docs
A box in which a single widget can be scrolled. This widget is useful when you have a single box that will normally...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Based on your example this should work:
That’s because you always set
_waitData
totrue
before checking it.