Run the loadMethod in ngInfiniteScroll only one time

<div >
<div infinite-scroll='loadMore()' infinite-scroll-distance='2'>
    <img ng-repeat='image in images' ng-src='http://placehold.it/225x250&text={{image}}'>
</div>

$scope.images = [1, 2, 3, 4, 5, 6, 7, 8];

    $scope.loadMore = function () {
        console.log('scroll');
        var last = $scope.images[$scope.images.length - 1];
        for (var i = 1; i <= 30; i++) {
            $scope.images.push(last + i);
        }
    };

Upon entering the page, the loadMore function is called. However, after scrolling down, it seems to no longer be triggered. What could be causing this behavior?

Answer №1

If the initial page load does not fill up the viewport height, the loadMore function will not be triggered. Add the attribute infinite-scroll-immediate-check="true" to ensure that items are filled on page load.

Here is the modified code:

<div>
    <div infinite-scroll='loadMore()' 
         infinite-scroll-distance='2' 
         infinite-scroll-immediate-check="true">
        <img ng-repeat='image in images' ng-src='http://placehold.it/225x250&text={{image}}'>
    </div>
</div>

For more information, refer to infinite-scroll-immediate-check.

Answer №2

<div infinite-scroll="functionName()" infinite-scroll-distance="1" infinite-scroll-container="'#yourContainer'" >

To enable infinite scroll, locate the specific container in your developer tools and assign it a name.

For more information and documentation, visit this link.

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

NodeJs causing issues with reloading AngularJs routes

I was able to successfully create a sample app by following a few examples, but I've encountered an issue that I'm struggling to resolve. In my Angular app, the routes work fine like this: - http://localhost:8888/#/login works However, when I re ...

What is the best way to reach the parent controller's scope within a directive's controller?

In a scenario where I have a custom directive nested inside a parent div with a controller that sets a variable value to its scope, like this: html <div ng-controller="mainCtrl"> <p>{{data}}</p> <myDirective oncolour="green" ...

Slicing an array in Javascript/Angular before it is officially initialized

Is it possible to specify the portion of an array to retrieve before making a $http GET request in Angular? I am aware of slicing arrays, but wondering if I can set this up in advance for better performance. In PHP, you can do something similar, but not ...

Is it possible to do bulk deletion in Flask Restless using AngularJS or JavaScript?

I am trying to implement bulk delete functionality in my AngularJS application by making an HTTP request to a Flask Restless API with version 0.17.0. While I know how to delete records one by one using their IDs in the URL, I am unsure if it is possible to ...

Dividing an AngularJS module across multiple iFrames on a single webpage

Currently, I am working on a web application that consists of 1 module, 5 pages, and 5 controllers. Each HTML page declares the same ng-app. These pages are loaded within widgets on a web portal, meaning each page is loaded within an iFrame in the portal. ...

Displaying Firebase snap.val using the ng-repeat directive

Just a quick question: I'm attempting to iterate through data in my $scope.discover using ng-repeat. Here is the code snippet I am using to fill that scope: const businessKey = '-KQ1hFH0qrvKSrymmn9d'; const rootRef = firebas ...

Angular JS allows you to easily remove the # symbol from a URL, improving the

I am encountering a problem with the "#" symbol in my angular js website's URL. I need to remove the # from the URL but the method provided isn't working and the site is not displaying properly. Can someone advise me on how to successfully remove ...

Looking to manipulate and update information within a JSON file using AngularJS

Exploring the world of AngularJS, I've tried searching online but haven't found much helpful information yet. This is the content of my retails.json file: { "categories": [ { "dept_id": "123", "category_na ...

Combining Rails API with AngularJS and IonicFramework

I'm embarking on a new project and feeling unsure about my chosen setup/approach. The project involves creating a list directory that doesn't require high computing power. My initial plan is to develop a website using Rails Api and AngularJs (al ...

Mastering Protractor's end-to-end control flow and managing time outs

When testing an angular app using protractor, I encountered a strange issue recently. Every now and then, or since a recent update, protractor seems to stall or slow down significantly. After investigating the problem, I discovered that a simple someEleme ...

Using AngularJS within XSLT: Unrecognized prefix 'true' encountered

I have a button that uses ng-repeat. Inside this button, I am applying an active class based on the default product. <button type="button" ng-model="selectedProductGroup" ng-repeat="item in pgroup |unique: 'Product' track by $index" ng-click= ...

The $mdSticky feature in AngularJS Material seems to be malfunctioning

It's been a challenge for me to get the md-toolbar to stay in the top position. I decided to create a custom directive using the $mdSticky service in AngularJS. var app=angular.module('app',['ngMaterial']); app.controller(&apos ...

Having trouble with Angular JS functionality

Today is my first day diving into AngularJS and I'm eager to learn more! Despite grasping the concept of how model-controller-views operate in AngularJS, I encountered an issue where the variables are not displaying as expected. Instead of the values, ...

IE9 not rendering inline styles properly when using AngularJS Directive

My directive is functioning well in Chrome, however in IE9 it displays '{{myappInitials.IconColor}' in the HTML: <tr ng-repeat="person in data.people"> <td class="text-left"> <div myapp-initials="person" ></div> ...

I am facing an issue where my AngularJS code is not executing properly on JSF

I'm trying to clear the text inside a textarea using AngularJS after typing and clicking on a button. Here's the link to the fiddle for reference: http://jsfiddle.net/aman2690/2Ljrp54q/10/ However, I keep encountering the following error messag ...

When sending JSON to API Controller, the C# model does not get bound

After searching through numerous posts, I can't figure out what mistake I've made. It seems like there's a minor issue that I just can't spot. Any guidance in the right direction would be greatly appreciated. I have an API controller s ...

Display the value beyond the ng-repeat loop

Is there a way to display the text {{Brand.BrandDetails.Text}} just once outside of the ng-repeat, while still allowing the repetition? <li ng-repeat="Brand in Brands"> <a href="#"> <img src="~/Images/{{Brand.BrandDetails. ...

Error: Trying to access properties of an undefined object (specifically 'promise.data.map')

Currently, I am in the process of writing unit tests for a project built with Angular version 1.2. For my controller tests, I have set up a mockService that returns a deferred promise. One of the service methods looks like this: function getItems() { ...

The binding in webstorm for AngularJS is not displaying correctly

Recently, I've started learning angularJS but I'm struggling with a particular issue: Everything works perfectly when using the official phonecat tutorial file. However, when I try to create my own project, the data binding doesn't display ...

Creating a Form with a Custom Format in AngularJS

Just starting out with AngularJS and currently working with ACTIVITI. I'm looking to create a form in a specific structure where each response follows this format: { "taskId" : "5", "properties" : [ { "id" : "room", ...