Comments (4)
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.
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'];
consider each orange block ng-infinite-scroll calling your function.
from nginfinitescroll.
I tried the same, but still it fires couple of times, what is the problem
from nginfinitescroll.
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)
- Fires Permanently (& Causes to Reload Models Within) HOT 2
- Infinite-scroll function is not called when page is resized HOT 1
- ngInfiniteScroll causes high CPU usage on Cordova Android app
- Custom defined modules with infinite scroll - how to set the throttle parameter HOT 1
- infinite-scroll function is not fired if jQuery is not explicitly imported on index.html
- ngInfiniteScroll is firing two times in the call stack for single initialisation HOT 1
- How do I get the latest version of ngInfiniteScroll without using bower? HOT 4
- When using 'infiniteScrollContainer' attribute the calculation isn't according to the chosen container
- does it support angular2? HOT 4
- Is this implementation affected by this chrome bug? HOT 1
- Mobile Scroll down - makes new objects load, but takes me all the way back to the start
- Download from sroze.github.io still linking 1.0.0
- Injecting this module causes browser to not load angular app. HOT 1
- path change while scrolling
- 模型管理各个模块没有关联选项可以选择
- ngInifinitescroll is not working HOT 1
- infinte-scroll not triggering when container is unbinded and then rebinded
- What is the license for this package? HOT 1
- How to preserve the scroll position when navigating to another page and come back to the first page.
- How to get the scroll position
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nginfinitescroll.