Comments (11)
I use infinite scrolling behaviour with vs-repeat. I just load more content when the user scrolls to the bottom and append those elements to the source array. But if you wanted the scroll to mimic like the entire collection of items is there then the vs-repeat
fill element would have to have a proper size. I'd go with providing that size to vs-repeat
rather then create fake items in the array. You're welcome to create a pull request on that if you are willing to implement this. And if you do remember that vs-repeat
has a mode when you provide it with vs-size-property
attribute. It also has to be taken into account.
from angular-vs-repeat.
Question about infinite scrolling you've done... How did you accomplish that with vs-repeat? I'm trying to use ngInfiniteScroll but that's not working for me because the way that it works and the way that vs-repeat work. Is there any way that I could pass vs-repeat a function to call when the user is x items away from the bottom? Would you accept a PR that would do this?
from angular-vs-repeat.
Hmm, looks to me that this could be accomplished fairly easy without modifying the library. My virtual scroll was fetching more elements when the user scrolled all the way down. So i set up an event listener for the scroll event and in thr handler i check the scroll position. If you want the fetching to be triggered when the user is 'x' items away you could set up a '$watch' on a proper scope and watch for 'startIndex' or 'endIndex' vs-repeat inner property. Then check if 'collectionLength - endIndex < x' fetch more elements.
from angular-vs-repeat.
Cool. Seems like that would work pretty well. I'm having internet issues right now preventing me from trying it out on jsbin, but I'll give it a shot. Looks promising though. Would probably be something to add to the docs as an example for sure.
from angular-vs-repeat.
Looks like this doesn't work with the current implementation. The problem is that vs-repeat
creates a child scope and I don't have access to the endIndex
that's created by the vs-repeat
's scope. We need to add that as an additional attribute to bind that properly. I'll make a PR for this and we'll see what you think.
from angular-vs-repeat.
Hmm,
you said that:
vs-repeat creates a child scope and I don't have access to the endIndex that's created by the vs-repeat's scope
As it's true that vs-repeat
created a scope, it is not true that you don't have access to it. At first i thought about accessing it via $$childHead
property on the parent scope, but that obviously is far from an elegant solution. But there is one very elegant. I have created a fiddle for you to check out how it's done: http://jsfiddle.net/tcv2oz41/1/
Basically the idea is to use ng-init
directive on the vs-repeat
element like this:
ng-init="setUpWatcher()"
and then in your controller write a function like this:
$scope.setUpWatcher = function(){
// this - is a reference to the scope that originally calls
// this method i.e. the vs-repeat scope
this.$watch('endIndex', function(val){
$scope.currentEndIndex = val;
});
};
from angular-vs-repeat.
That's a very interesting approach.... I believe it is acceptable. Though I
believe that my PR is a more elegant and straightforward solution. Is there
a reason you would prefer to avoid merging my PR?
Kent C. Dodds
https://twitter.com/kentcdodds
https://plus.google.com/114245123507194646768 [email protected]
http://www.linkedin.com/profile/view?id=67772537
http://mormon.org/me/1J5N/Kent
On Wed, Sep 10, 2014 at 12:31 AM, kamilkp [email protected] wrote:
Hmm,
you said that:vs-repeat creates a child scope and I don't have access to the endIndex
that's created by the vs-repeat's scopeAs it's true that vs-repeat created a scope, it is not true that you
don't have access to it. At first i thought about accessing it via
$$childHead property on the parent scope, but that obviously is far from
an elegant solution. But there is one very elegant. I have created a fiddle
for you to check out how it's done: http://jsfiddle.net/tcv2oz41/1/Basically the idea is to use ng-init directive on the vs-repeat element
like this:ng-init="setUpWatcher()"
and then in your controller write a function like this:
$scope.setUpWatcher = function(){
// this - is a reference to the scope that originally calls
// this method i.e. the vs-repeat scope
this.$watch('endIndex', function(val){
$scope.currentEndIndex = val;
});};—
Reply to this email directly or view it on GitHub
#10 (comment)
.
from angular-vs-repeat.
Well the library shall be kept simple. If something can be implemented in a clean way without the need to extend the library that's what i prefer. Otherwise all those little extensions will eventually take their toll on performance for user that don't use nor need those features. And by the way, you set up a $watch
there which is not needed because startIndex
and endIndex
is basically changed only in one place in code so this function could be called directly from there. Also the $parse($attrs.vsOnIndexChange)
in every watcher handler is inefficient. This expression could be parsed once and then the result of parsing (a function) called on $scope
in the handler.
from angular-vs-repeat.
All terrifically valid points. Thanks for the help!
from angular-vs-repeat.
One more thing. You can write a reusable directive like this:
directive('onVsIndexChange', ['$parse', function($parse){
return function($scope, $element, $attrs){
var expr = $parse($attrs.onVsIndexChange);
var fn = function(){
expr($scope);
}
$scope.$watch('startIndex', fn);
$scope.$watch('endIndex', fn);
};
}]);
and use it like that:
<div vs-repeat on-vs-index-change="indexChanged(startIndex)">
<!-- ... -->
</div>
That way you are not extending the library but at the same time you have basically the exact same api as the one that you prefer.
from angular-vs-repeat.
I have learned a few very useful techniques from you here! Thanks!
from angular-vs-repeat.
Related Issues (20)
- Demo page still uses version 1.1.7
- newer 2.0.X versions wont run with javascript HOT 1
- items stuck between adding/removing cause scroll flicker HOT 2
- is it possible to have multiple block of vs-repeat all specifying the same parent? HOT 1
- scroll horizontal doesn't show all elements
- Unable import the angular-vs-import
- Bug Ionic 1. Version 2+ does not work with Ionic 1 HOT 1
- [Question] - How to use variable size in the most recent version HOT 4
- [Question] - how to tell which items are visible HOT 1
- Content is offset from screen on mobile after scrolling a long list HOT 1
- two ng-repeat in vs-repeat
- one issue related to the fullcalendar use
- vs-repeat on object HOT 1
- Displaying a heading with nested repeats
- how ti use with angularJs datatable?
- bower release for 2.0.13
- angular 1.5?
- Inability to use $index
- Everything rendered or only firsts HOT 1
- The horizontal state does not work at runtime
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 angular-vs-repeat.