Infinite scroll feature in AngularJS triggers function calls while scrolling up and down

I have incorporated the infinite scroll feature from version 1.1.0 into my project. The scenario involves a table where contents are loaded dynamically as the user scrolls down.

A similar implementation can be seen in this example, where data is added to an array and displayed inside a div, functioning as expected.

However, when attempting to replicate this on another page, I noticed that the showMore() function is triggered not only on scrolling down but also on scrolling up. Below is the structure of the table:

<table>
    <thead>
        <tr>
            <th>Some heading</th>       
            <th>Some other heading</th>
        </tr>
    </thead>
    <tbody>
      <div infinite-scroll="showMore()" infinite-scroll-distance="3" infinite-scroll-disabled='infiniteScrollDisabled'>
        <tr ng-repeat="r in report">
            <td>{{$index}}</td>    
            <td">{{r.someData}}</td>
        </tr>
      </div>
    </tbody>
</table>

I am perplexed as to why the showMore() function is executed even upon scrolling up. Could it possibly be related to the structure of the table? Any insights would be appreciated.

Answer №1

To solve the issue, simply relocate the

<div infinite-scroll="showMore()" infinite-scroll-distance="3" infinite-scroll-disabled='infiniteScrollDisabled'>

outside of the <table>.....</table> elements.

Answer №2

After encountering an issue on github, I came across a solution that worked for me. Check it out here: https://github.com/sroze/ngInfiniteScroll/issues/157

<div class="constrained" ng-controller="MyCtrl">
    <table infinite-scroll="increaseLimit()" infinite-scroll-container='".constrained"'>
        <tr ng-repeat="item in items | limitTo:barLimit">
            <td>Number</td>
            <td>{{item.number}}</td>
        </tr>
    </table>
</div>

Credit goes to BenjaminWFox for this solution.

To see this in action and learn more about filtering, check out this jsFiddle: https://jsfiddle.net/lisapfisterer/Lu4sbxps/

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

JavaScript tabs function malfunctioning upon page load

I attempted to implement tabs on my website using this example: http://www.w3schools.com/howto/howto_js_tabs.asp Although everything is functioning correctly, the default tab isn't opening as expected. The tab opens, but the header color does not get ...

Vue.js - The dissonance between data model and displayed output

Below is a simplified example of my issue: <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script> <script src="https://unpkg.com/vue/dist/vue.js"></script> ...

React Native - Invariant Violation: Objects cannot be used as a React Child (Utilizing Node.js for the backend)

Trying to calculate the total sum of orders and their quantity using Node JS on the backend. However, encountering issues with the fetch functions not working properly or missing something unknown. The API works as expected when tested in Postman, but err ...

Issue with Angular: Undefined Variable

After starting to work with Angular Routes recently, I encountered a situation where data was getting lost on refresh. The solution suggested to me was to use resolve, which seemed promising but I am struggling to implement it successfully. .config([&a ...

Issue with external variable not being updated properly in success callback

Working through an array of data, I make updates to a variable called commentBody during each iteration. However, even though the variable is modified within the loop itself, whenever I try to access it from inside a success callback, it consistently show ...

What is the process of submitting a query request and then saving it as a variable in javascript?

As a beginner in SQL, JSON, and Fusion Table, I am looking to extract data from a Fusion Table and store it in a JavaScript variable, allowing me to display the data within a div element. This is the progress of my JavaScript code so far: var TopCity; To ...

The event.submit/return true in JS/jQuery is not functioning as expected

Could someone lend a hand? I'm struggling with a validation script that checks an email form for content and a valid email. It's functioning correctly, but it's not submitting the form even when everything is correct - it just removes the er ...

The JQuery pagination feature fails to function properly once an AJAX load is initiated

I am using jspages.js to implement pagination with jQuery. Everything works fine when the page is initially loaded. However, I encounter an error when the content for pagination is loaded after an ajax call. The plugin does not seem to work as expected. ...

What is the best way to ensure that the bootstrap nav tab content fits perfectly on one line?

Check out this bootstrap navbar example You can see a screenshot here. <ul class="nav nav-tabs" style="display: inlne-block"> <li class="nav-item" style="text-align: center; display: inline;"> <div> <a class="nav ...

Changing the contents of a global array in JavaScript

$(document).ready(function(){ var currArray=null; var group=null; var admin=null; var equipment=null; var student=null; console.log("after get array info"); for(var i=0; i<equipment.length; i++) { console.log("equipment at index after get array info ...

Integrating Javascript and JQuery in Reactjs: A Comprehensive Guide

Currently, I am working with ReactJS and utilizing the Next.js framework. My goal is to implement the provided code snippet in index.js to display data (day, month, etc.). How should I go about achieving this? Here is the code snippet: <script> fun ...

The customization of a class within an array loop is not functioning properly

I'm facing an issue where I've added a class (question) to each element in an array, and the loop is running smoothly. However, I'm having trouble getting jQuery to recognize the class - it's almost as if it doesn't exist... I sus ...

Is it possible to activate multiple animations simultaneously within a single div using UIKit?

I recently started developing a to-do web application and was looking to enhance its appearance with some animations using UIKit. Currently, I have an animation that toggles when the todo-items are brought into view: <div class="todo-items uk-anim ...

Unable to update state in my React app when clicking on a button

There is a requirement for a button click to filter the job-card array by one specific category. For example, clicking on the button "Marketing" should only show jobs from the array that have the property "jobstags: Marketing". I followed a similar procedu ...

Utilize Javascript to locate the image width and assign it to the wrapper divs in WordPress

I am trying to figure out how to set the wrapper divs' widths equal to the size of the images (featured images) they contain so that they are evenly spaced from each other. I came across a potential solution here: (solution at the bottom), but I am ...

Interactive Thumbnail Selection for HTML5 Video

Having trouble with creating thumbnails? I managed to solve the cross-domain issue using an html2canvas PHP proxy. No error messages in the Console, but the thumbnails are unfortunately not showing up - they appear transparent or white. Here is a snippet ...

Interactive React Dropdown Component

As a relatively new React user, I am attempting to develop a custom component that will showcase a list of items within a select menu. The goal is to allow the user to make a selection from the menu and then click an "Add" button below it. Upon clicking th ...

Uploading files using Ajax in the Laravel framework

I am attempting to utilize ajax to upload a file in Laravel. $("#stepbutton2").click(function(){ var uploadFile = document.getElementById("largeImage"); if( ""==uploadFile.value){ } else{ v ...

While working on a project in React, I successfully implemented an async function to fetch data from an API. However, upon returning the data, I encountered an issue where it was displaying as a

I am working with React and TypeScript and have the following code snippet: const fetchData = async () => { const res: any = await fetch("https://api.spotify.com/v1/search?q=thoughtsofadyingatheist&type=track&limit=30", { met ...

Facilitate parent directory navigation

Hello everyone! I am currently developing an express application. At the top of my express file, I added this line to serve all static files from my working directory: app.use(express.static(__dirname)); Now, I am trying to send a file that is located in ...