Giter VIP home page Giter VIP logo

Comments (4)

BinaryMuse avatar BinaryMuse commented on June 7, 2024 5

Hey, @gnesher,

The directive was designed to make as few assumptions about what you're doing inside the callback function as possible. As such, if you're doing asynchronous work and you want to temporarily disable the callback (e.g. you don't want the directive to fire the callback, even if the user is scrolling), you can assign a dynamic value to infinite-scroll-disabled. The async demo on the web site shows such an example; here are the relevant snippets:

HTML:

<div infinite-scroll='nextPage()' infinite-scroll-disabled='busy'>
  ...
</div>

JavaScript:

app.controller('DemoController', function($scope, $http) {
  $scope.busy = false;

  $scope.nextPage = function() {
    // this is a safeguard; the callback shouldn't actually be called
    if ($scope.busy) return;
    $scope.busy = true;

    $http.jsonp(url).success(function(data) {
      ...
      $scope.busy = false;
    });
  };
});

Of course, you can (and should) wrap up all the logic for your data into a service; the demo does it all in a controller for simplicity.

Let me know if you still have questions or have any problems with this.

from nginfinitescroll.

graingert avatar graingert commented on June 7, 2024 1

I'd recommend using 'async/cargo' instead:

import cargo from 'async/cargo';

export default function DemoController($scope, $http) {
  const cargo = async.cargo(function(tasks, callback) {
      $http.jsonp(url).success(function(data) {
        $scope.data = data;
        callback();
      });
  });

  $scope.nextPage = function() {
    cargo.push({});
  };
});

DemoController.inject = ['$scope', '$http'];

cargo animation

consider each orange block ng-infinite-scroll calling your function.

from nginfinitescroll.

selvakumarpandiyan avatar selvakumarpandiyan commented on June 7, 2024

I tried the same, but still it fires couple of times, what is the problem

from nginfinitescroll.

christiaanwesterbeek avatar christiaanwesterbeek commented on June 7, 2024

I tried the same, and it fixed my problem of firing a couple of times.

Here's the updated demo link: http://sroze.github.io/ngInfiniteScroll/demo_async.html

from nginfinitescroll.

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.