How to: Execute infinite scroll using AngularJS and change route on every new post
Problem
I want to build something like qz.com
The url changes(without page refresh) when you scroll down and the data gets appended to the last post. Trying to build it over angular-express-seed.
Any pointers or tutorials will help.
EDIT: Found a fiddle here http://jsfiddle.net/fotuzlab/nES2q/ (forked from original)
elm.bind('scroll', function() {
if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) {
scope.$apply(attr.whenScrolled);
}
});
Seems it can do the job but now elm.bind is not working for some reason. Any other method to so this?
Solution
Answering own question in case it helps someone.
Instead of writing a complete custom directive to achieve the purpose, integrated a controller with inview directive.
Added div in partial which calls a controller loadnext().
Controller calculates the next article and pushes it in view.
$scope.posts.push(data)
This can be seen working at http://sarus.srijanlabs.com
This project has been open sourced under the name Sarus. Complete code can be checked there https://github.com/srijanlabs/sarus
All thanks to my collegue @whizcreed to get this working.
Discussion
View additional discussion.