ngx-infinite-scroll event fails to trigger upon scrolling to the end

I am currently facing an issue while trying to implement infinite scroll using ngx-infinite-scroll in an Angular 4 application. Despite following the documentation and configuring the height of the element while setting scrollWindow to false, the trigger is not happening as expected. What could I possibly be doing wrong here?

To demonstrate the problem, I have created a Plnkr with the reproduction of the issue.

HTML:

<div class="search-results"
     infinite-scroll
     [infiniteScrollDistance]="0.1"
     [infiniteScrollThrottle]="10"
     [scrollWindow]="false"
     (scrolled)="onScrollDown()">
  <p *ngFor="let i of is">
    {{i}}
  </p>
</div>

CSS:

.search-results {
  height: 100px;
  overflow: scroll;
}

Component:

protected is = ['Item1', 'Item2', 'Item3'];

onScrolledDown() {
    console.log("scrolled");
}

Answer №1

I have discovered a clever workaround that resolves the issue at hand. By adjusting the infiniteScrollThrottle to 0 and creating your own throttling method, the issue can be fixed effectively.

Here is a step-by-step guide on how to implement this solution:

Within the HTML code, incorporate the following attributes:

[infiniteScrollThrottle]="0"
(scrolled)="loadMore()"

Additionally, in the TypeScript file, establish your own throttling condition within the loadMore() function:

loading = false;
loadingThrottle = 300;

loadMore() {
    if (!this.loading) {
      this.loading = true;

      window.setTimeout(() => {

        // Insert your loading logic here..

        this.loading = false;
      }, this.loadingThrottle);
   }
}

Answer №2

To ensure proper functionality, when using bootstrap 4, make sure to disable flex.

.search-results {
  height: 100px;
  overflow: scroll;
  flex: none;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Angular application in production is linked to a local Express server rather than the intended production server

Revision 2 Upon further experimentation, I discovered that the site was linking to the Express server on my development computer. When I execute node ./bin/www on the dev machine, the AWS site interfaces with it smoothly and operates without any issues. ...

Angular will continue to stay on the current page unless the form is completed

Once a user logs in, they are directed to a form where they can enter their name and username. http://localhost:4200/form I need to ensure that the user fills out the form before being redirected to another page, even if they try to change the URL. In m ...

The error type currently displayed relates to window['angularComponentReference']

Currently, I am attempting to incorporate NgZone into my Angular project: constructor( private fishboneService: FishboneService, private zone: NgZone, ) { window['angularComponentReference'] = { zone: this.zone, componentFn: (val ...

How to modify attributes using ng-content in Angular 2

Looking for a way to modify the attribute of the top div within the ng-content in my code. Here's an example snippet: <ng-container> <ng-content select="[content-body]"></ng-content> </ng-container> For instance, I want t ...

What is the method for utilizing enum values as options for a variable's available values?

I'm curious about using enum values in TypeScript to restrict the possible values for a variable. For example, I have an enum named FormType with Create and Update options. Is there a way to ensure that only these enum values are used? enum FormType { ...

Ngrx 8: Strategies for mocking various selectors with distinct return values

I am currently in the process of writing unit tests for an Angular 8 component that has a dependency on an ngrx store. I have multiple selectors set up within the ngOnInit function and I am looking to mock these selectors using the overrideSelector method. ...

What is the best way to save data from a Firebaselistobservable into an array?

I've been attempting to transfer data from Firebase to an array using Angular 2, but I'm facing difficulties in pushing the data into the array. Below is the code snippet: Variables: uid: string = ''; agencyItems: FirebaseListObserva ...

Setting up Next Js to display images from external domains

Encountering an issue with my next.config.js file while working on a project with Next.js in TypeScript. This project involves using ThreeJs, @react-three/fiber, and @react-three/drei libraries. Additionally, I need to include images from a specific public ...

Angular application unable to invoke the Web API GET method

Just starting out with Angular. I've got a WebAPI controller set up with a get method that returns data. Everything runs smoothly when I access it from the browser directly. But for some reason, when I try to call the same method from my Angular ap ...

Transforming a material-ui component from a class to a function

Currently, I am in the process of learning material-ui, and it seems that most of the code examples I come across are based on classes. However, the new trend is moving towards using functions instead of classes due to the introduction of hooks. I have be ...

Puppeteer: What is the best way to interact with a button that has a specific label?

When trying to click on a button with a specific label, I use the following code: const button = await this.page.$$eval('button', (elms: Element[], label: string) => { const el: Element = elms.find((el: Element) => el.textContent === l ...

Setting a border on a specific column in ag-grid is a simple task that can help you customize

I have a table where the first set of columns differs from the rest. I am looking to emphasize this distinction by adding a vertical border on the right side of the specific column to highlight it both in the header and rows. Our setup includes using the ...

The attribute 'id' cannot be found in the class 'Foods'

After examining my code below, I am attempting to remove clients from my data table by using checkboxes. Whenever I check a checkbox, I notice in the console that the object's properties are retrieved from the database. My goal is to delete by id, but ...

Unable to access property value following AJAX call

Here is my code snippet: constructor(props: any) { super(props); this.state = { list: [], }; } public componentWillMount() { this.loadData(); } public loadData = () => { axios.get(someURL) .then((response) = ...

Creating an application using AngularJS 4 and the Express generator

Recently, I successfully created a basic angular 4 application using this helpful tutorial: https://scotch.io/tutorials/mean-app-with-angular-2-and-the-angular-cli My next challenge is integrating the angular 4 app with an express application generated b ...

The Datepicker label in Angular (^16.0.0) Material (^16.1.0) is floating at an unexpectedly high position

I'm struggling to implement a mat-datepicker in my Angular page because the label is floating too high. When I select a date, the label ends up getting pushed under the top bar of the page. I can't figure out what's causing this issue; help ...

Struggling to find a solution for directing to the featured homes page without the content overlapping with my navbar and search component. Any assistance would be greatly

Looking for assistance with routing to the featured homes page without the content overlapping my navbar and search component. I simply want it to direct to a new URL without importing the components unless specifically needed. Check out this link I suspe ...

Comprehending the concepts of Observables, Promises, using "this" keyword, and transferring data within Angular with TypeScript

I am trying to figure out why I keep receiving the error message: "Uncaught (in promise): TypeError: this.dealership is undefined" when working with the authentication.service.ts file. export class AuthenticationService { private currentUserSubject: ...

Using react-google-charts to create visually appealing dual-Y stacked bar charts

I am currently working on developing a bar chart with specific criteria in mind. My data follows the format: [month, region, totalSalesForCompanyA, totalSalesForCompanyB] I have successfully implemented the following charts: A dual-Y bar chart where mo ...

What is the best way to send an array of locationIds to the getLocationData service?

Seeking Assistance on Sending an Array of Location IDs to a Service I currently have an array consisting of location IDs. locationArr=[40871, 60009, 38149, 40868, 43240, 15299, 53897, 40976, 38151, 23183, 38152, 78579, 23180, 40977, 23176, 39565, 40884, ...