Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
ngx-infinite-scroll
Advanced tools
An infinite scroll directive for Angular compatible with AoT compilation and Tree shaking
The ngx-infinite-scroll package is an Angular directive that allows you to implement infinite scrolling in your Angular applications. It provides a simple way to load more data as the user scrolls down the page, enhancing the user experience by avoiding the need for pagination.
Basic Infinite Scroll
This feature allows you to implement basic infinite scrolling. The `infiniteScroll` directive is added to a container, and the `scrolled` and `scrolledUp` events are used to load more data when the user scrolls down or up, respectively.
<template>
<div infiniteScroll
[infiniteScrollDistance]="2"
[infiniteScrollUpDistance]="1.5"
[infiniteScrollThrottle]="300"
(scrolled)="onScrollDown()"
(scrolledUp)="onScrollUp()">
<!-- content here -->
</div>
</template>
<script>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
onScrollDown() {
console.log('scrolled down!!');
// Load more data here
}
onScrollUp() {
console.log('scrolled up!!');
// Load more data here
}
}
</script>
Custom Scroll Distance
This feature allows you to customize the scroll distance at which the `scrolled` event is triggered. In this example, the `infiniteScrollDistance` is set to 1, meaning the event will be triggered when the user scrolls to the bottom of the container.
<template>
<div infiniteScroll
[infiniteScrollDistance]="1"
(scrolled)="onScroll()">
<!-- content here -->
</div>
</template>
<script>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
onScroll() {
console.log('scrolled!!');
// Load more data here
}
}
</script>
Throttle Scroll Events
This feature allows you to throttle the scroll events to improve performance. The `infiniteScrollThrottle` input is used to specify the delay in milliseconds between successive scroll events. In this example, the scroll events are throttled to 200 milliseconds.
<template>
<div infiniteScroll
[infiniteScrollThrottle]="200"
(scrolled)="onScroll()">
<!-- content here -->
</div>
</template>
<script>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
onScroll() {
console.log('scrolled!!');
// Load more data here
}
}
</script>
The ngx-scroll-event package provides a simple way to handle scroll events in Angular applications. It allows you to detect when the user scrolls to the top, bottom, or a specific position of a container. Compared to ngx-infinite-scroll, ngx-scroll-event offers more granular control over scroll events but does not provide built-in infinite scrolling functionality.
The ngx-virtual-scroller package is an Angular component that provides virtual scrolling for large lists. It renders only the visible items in the list, improving performance for large datasets. While ngx-virtual-scroller focuses on optimizing rendering performance, ngx-infinite-scroll is more about loading additional data as the user scrolls.
The angular2-infinite-scroll package is another Angular directive for implementing infinite scrolling. It offers similar functionality to ngx-infinite-scroll, allowing you to load more data as the user scrolls. However, ngx-infinite-scroll is more actively maintained and has better documentation.
Inspired by ng-infinite-scroll directive for angular (> 2, 4).
Supports Angular > 4
For Angular version <= 2.3.1, you can use npm i angular2-infinite-scroll
(latest version is 0.3.42) - please notice the angular2-infinite-scroll package is deprecated
I'm a Senior Javascript Engineer & A Front End Consultant at Orizens. My services include:
npm install ngx-infinite-scroll --save
Currently supported attributes:
By default, the directive listens to the window scroll event and invoked the callback.
To trigger the callback when the actual element is scrolled, these settings should be configured:
First, import the InfiniteScrollModule to your module:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { InfiniteScrollModule } from 'ngx-infinite-scroll';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppComponent } from './app';
@NgModule({
imports:[ BrowserModule, InfiniteScrollModule ],
declarations: [ AppComponent, ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
platformBrowserDynamic().bootstrapModule(AppModule);
In this example, the onScroll callback will be invoked when the window is scrolled down:
import { Component } from '@angular/core';
@Component({
selector: 'app',
template: `
<div class="search-results"
infiniteScroll
[infiniteScrollDistance]="2"
[infiniteScrollThrottle]="300"
(scrolled)="onScroll()">
</div>
`
})
export class AppComponent {
onScroll () {
console.log('scrolled!!')
}
}
in this example, whenever the "search-results" is scrolled, the callback will be invoked:
import { Component } from '@angular/core';
@Component({
selector: 'app',
styles: [
`.search-results {
height: 20rem;
overflow: scroll;
}`
],
template: `
<div class="search-results"
infiniteScroll
[infiniteScrollDistance]="2"
[infiniteScrollThrottle]="500"
(scrolled)="onScroll()"
[scrollWindow]="false">
</div>
`
})
export class AppComponent {
onScroll () {
console.log('scrolled!!')
}
}
In this example, the onScrollDown callback will be invoked when the window is scrolled down and the onScrollUp callback will be invoked when the window is scrolled up:
import { Component } from '@angular/core';
import { InfiniteScroll } from 'ngx-infinite-scroll';
@Component({
selector: 'app',
directives: [ InfiniteScroll ],
template: `
<div class="search-results"
infiniteScroll
[infiniteScrollDistance]="2"
[infiniteScrollUpDistance]="1.5"
[infiniteScrollThrottle]="500"
(scrolled)="onScrollDown()"
(scrolledUp)="onScrollUp()">
</div>
`
})
export class AppComponent {
onScrollDown () {
console.log('scrolled down!!')
}
onScrollUp () {
console.log('scrolled up!!')
}
}
FAQs
[![Build Status](https://travis-ci.org/orizens/ngx-infinite-scroll.svg?branch=master)](https://travis-ci.org/orizens/ngx-infinite-scroll) [![Backers on Open Collective](https://opencollective.com/ngx-infinite-scroll/backers/badge.svg)](#backers) [![Sponso
The npm package ngx-infinite-scroll receives a total of 142,047 weekly downloads. As such, ngx-infinite-scroll popularity was classified as popular.
We found that ngx-infinite-scroll demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.