npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

Iโ€™ve always been into building performant and accessible sites, but lately Iโ€™ve been taking it extremely seriously. So much so that Iโ€™ve been building a tool to help me optimize and monitor the sites that I build to make sure that Iโ€™m making an attempt to offer the best experience to those who visit them. If youโ€™re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, ๐Ÿ‘‹, Iโ€™m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If youโ€™re interested in other things Iโ€™m working on, follow me on Twitter or check out the open source projects Iโ€™ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soonโ€“ish.

Open Software & Tools

This site wouldnโ€™t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you ๐Ÿ™

ยฉ 2025 โ€“ Pkg Stats / Ryan Hefner

ng-inf-scroll

v0.0.1

Published

`ng-inf-scroll` is a lightweight, extremely performant ๐Ÿš€ Angular library designed to seamlessly implement infinite scroll functionality in your Angular applications. In this blog post, I'll walk you through how to integrate infinite scrolling into your A

Downloads

7

Readme

Adding Infinite Scroll in Angular with ng-inf-scroll

ng-inf-scroll is a lightweight, extremely performant ๐Ÿš€ Angular library designed to seamlessly implement infinite scroll functionality in your Angular applications. In this blog post, I'll walk you through how to integrate infinite scrolling into your Angular applications using ng-inf-scroll.

What is ng-inf-scroll?

ng-inf-scroll is a lightweight, extremely performant Angular library designed to seamlessly add infinite scroll functionality to your Angular applications. With easy-to-use services and directives, you can use ng-inf-scroll on both the window (root element) and any container element within your application.

Installation

To get started, install ng-inf-scroll using npm:

npm install ng-inf-scroll

Usage

There are two main ways to use the ng-inf-scroll library:

  1. Infinite Scroll on the window (root element)
  2. Infinite Scroll on a container element

Let's dive into both approaches.

1. Infinite Scroll on the Window (Root Element)

If you want infinite scroll to work on the entire window, inject the ViewportInfScroll service into your component and listen to the scrolled observable.

import { Component, OnInit, OnDestroy, inject } from '@angular/core';
import { Subscription } from 'rxjs';
import { ViewportInfScroll } from 'ng-inf-scroll';

@Component({
  selector: 'some-page',
  template: ' <p> Page content </p> ',
})
export class SomePageComponent implements OnInit, OnDestroy {
  viewportInfScroll = inject(ViewportInfScroll);
  sub: Subscription;

  ngOnInit() {
    this.sub = this.viewportInfScroll.scrolled().subscribe(() => {
      this.loadMore();
    });
  }

  loadMore() {
    // Load data
  }

  ngOnDestroy() {
    this.sub.unsubscribe();
  }
}

Don't forget to unsubscribe from the observable in the ngOnDestroy callback to clean up the listener.

2. Infinite Scroll on a Container Element

If you have a specific container element where you want to add infinite scroll, you can use the infScroll directive. This is useful when scrolling should be limited to a particular section of the page.

Here's an example:

import { Component } from '@angular/core';
import { InfScroll } from 'ng-inf-scroll';

@Component({
  selector: 'some-page',
  styles: [
    `
      .container {
        height: 200px;
        overflow-y: auto;
      }
    `,
  ],
  template: `
    <div class="container" infScroll (scrolled)="loadMore()">
      <h1 *ngFor="let item of data; trackBy: trackByFn">{{ item }}</h1>
    </div>
  `,
  standalone: true,
  imports: [InfScroll],
})
export class SomePageComponent {
  data = new Array(100).fill(0).map(() => Math.random());

  loadMore() {
    // Load more data logic here
  }

  trackByFn(index: number) {
    return index;
  }
}

Options

ng-inf-scroll comes with configurable options that help customize the infinite scroll behavior. Here are the available properties:

  • orientation: ('x' | 'y') - The default is 'y', which means vertical scrolling. Use 'x' for horizontal scrolling.
  • autoStop: (boolean) - Default is true. If set to true, the scrolled event will not emit if the container's height remains unchanged after the last emission. For instance, if the scrolled event is triggered, and you fetch data from the server but the response is empty, the container's height will stay the same. This indicates that you've reached the end of the infinite scroll.
  • offsetPercentage: (number) - Default is 20. It defines when the scrolled event should be emitted, based on the percentage of the container's scroll height. For example, initially, your container's scroll height might be 300px. As you load more data through infinite scrolling, the scroll height increases to 1000px. This setting ensures the scrolled event is emitted consistently at the same relative scroll position, regardless of the container's changing height.

Override Default Options

To override the default options globally, you can use the provideInfScroller function in the appConfig.

import { ApplicationConfig } from '@angular/core';
import { provideInfScroller } from 'ng-inf-scroll';

export const appConfig: ApplicationConfig = {
  providers: [
    provideInfScroller({
      autoStop: false,
      offsetPercentage: 30,
    }),
  ],
};

This allows you to modify how the infinite scroll behaves globally, ensuring it meets your application's specific requirements.