Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to: Execute infinite scroll using AngularJS and change route on every new post

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?

Problem courtesy of: fotuzlab

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.

  1. Added div in partial which calls a controller loadnext().

  2. 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.

Solution courtesy of: fotuzlab

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How to: Execute infinite scroll using AngularJS and change route on every new post

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×