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

angular-lazy-for

v1.1.5

Published

Similar to ngFor but only renders items that are visible.

Downloads

53

Readme

lazyFor

lazyFor is an Angular 2+ directive that can be used in place of ngFor. The main difference is that lazyFor will only render items when they are visible in the parent element. So as a user scrolls, items that are no longer visible will be removed from the DOM and new items will be rendered to the DOM.

Sample Usage

Plunker Demo

Install with npm install --save angular-lazy-for

app.module.ts

import {NgModule} from '@angular/core';
import {LazyForModule} from 'angular-lazy-for';

@NgModule({
  declarations: [/*...*/],
  imports: [
    //...
    LazyForModule
  ],
  providers: [/*...*/],
  bootstrap: [/*...*/]
})
export class AppModule {
}

Template Input

<ul style="height: 30px; overflow-y: auto">
  <li *lazyFor="let item of [1,2,3,4,5,6]" style="height: 10px;">
    {{item}}
  </li>
</ul>

DOM Output

<ul>
  <li style="height: 20px"></li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
  <li style="height: 10px"></li>
</ul>

When to use lazyFor

  • When you know the size of the iterable and you only want to create DOM elements for visible items
  • Fix performance issues with page load time
  • Fix change detection performance issues

When not to use lazyFor

  • Not meant to replace ngFor in all cases. Only use lazyFor if you have performance issues
  • Not an infinite scroll. don't use it if you don't know the total size of the list
  • Doesn't currently support loading items asynchronously. Although support for this may be added in the future
  • This directive does some DOM manipulation so it won't work if your Angular app runs in a web worker or if you use Angular Universal

Performance

lazyFor can improve performance by preventing unnecessary content from being rendered to the DOM. This also leads to fewer bindings which reduces the load on change detection. Using ngFor is usually very fast but here is a casae where it has a noticeable performance impact:

Plunker Performance Demo

Optional Parameters

withHeight

This directive will try to figure out the height of each element and use that number to calculate the amount of spacing above and below the items. If you are having issues with the defualt behaviour you can specify an explicit height in pixels.

<div *lazyFor="let item of items, withHeight 30"></div>

inContainer

lazyFor needs to know which element is the scrollable container the items will be inside of. By default it will use the parent element but if this is not the right element you can explicitly specify the container.

<div style="overflow: auto" #myContainer>
    <div>
        <div *lazyFor="let item of items, inContainer myContainer"></div>
    </div>
</div>

withTagName

This directive works by creating an empty element above and below the repeated items with a set height. By default these buffer elements will the use the same type of tag that lazyFor is on. However you can specify a custom tag name with this parameter if needed.

Template

<ul>
  <li *lazyFor="let item of items, withTagName 'div'"></li>
<ul>

DOM Output

<ul>
  <div height="..."></div>
  <li></li>
  <li></li>
  <li></li>
  <div height="..."></div>
<ul>