All Projects → robianmcd → angular-lazy-for

robianmcd / angular-lazy-for

Licence: other
Angular 2+ directive that takes an iterable and renders visible items to the DOM

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to angular-lazy-for

Angular Playground
A drop in app module for working on Angular components in isolation (Angular version 2.x and above).
Stars: ✭ 414 (+696.15%)
Mutual labels:  angular-directives
Ng Focus On
A directive to make angular elements focusable
Stars: ✭ 51 (-1.92%)
Mutual labels:  angular-directives
Angular Surveys
Angular survey / form builder inspired by Google Forms
Stars: ✭ 219 (+321.15%)
Mutual labels:  angular-directives
Angular Datepicker
Angularjs datepicker module, generate a datepicker on your input element - https://720kb.github.io/angular-datepicker
Stars: ✭ 486 (+834.62%)
Mutual labels:  angular-directives
Ng Zorro Antd
Angular UI Component Library based on Ant Design
Stars: ✭ 7,841 (+14978.85%)
Mutual labels:  angular-directives
Material
A lightweight Material Design library for Angular based on Google's Material Components for the Web.
Stars: ✭ 143 (+175%)
Mutual labels:  angular-directives
angular-openweather-app
A weather forecast app written in AngularJS
Stars: ✭ 54 (+3.85%)
Mutual labels:  angular-directives
ngx-vant
Lightweight Mobile UI Components built on Vant and Angular
Stars: ✭ 34 (-34.62%)
Mutual labels:  angular-directives
Ngx Infinite Scroll
Infinite Scroll Directive for Angular
Stars: ✭ 1,024 (+1869.23%)
Mutual labels:  angular-directives
Angular Query Builder
Dynamic query building UI written in Angular.
Stars: ✭ 211 (+305.77%)
Mutual labels:  angular-directives
Ng Zorro Antd Mobile
A configurable Mobile UI components based on Ant Design Mobile and Angular. 🐜
Stars: ✭ 709 (+1263.46%)
Mutual labels:  angular-directives
Angular Datetime Range
📅 Angular directive for datetime range input
Stars: ✭ 27 (-48.08%)
Mutual labels:  angular-directives
Angular Promise Buttons
Chilled loading buttons for AngularJS
Stars: ✭ 156 (+200%)
Mutual labels:  angular-directives
Ng Pageslide
AngularJS sliding panel for serving additional content from off the page
Stars: ✭ 464 (+792.31%)
Mutual labels:  angular-directives
Ngx Quill Editor
🍡@quilljs editor component for @angular
Stars: ✭ 234 (+350%)
Mutual labels:  angular-directives
Angular Tooltips
Angularjs tooltips module, add tooltips to your elements - https://720kb.github.io/angular-tooltips
Stars: ✭ 357 (+586.54%)
Mutual labels:  angular-directives
Semanticui Angular
Angular Directives for Semantic UI
Stars: ✭ 58 (+11.54%)
Mutual labels:  angular-directives
angular-fan-menu
Cool Menu component using Angular 1 for web and mobile.
Stars: ✭ 15 (-71.15%)
Mutual labels:  angular-directives
angular-datetime-inputs
📅 Angular directives for datetime inputs
Stars: ✭ 20 (-61.54%)
Mutual labels:  angular-directives
Angular Fx
Angular CSS3 animation directives (ngfx-bounce, ngfx-shake, ngfx-flip, ngfx-pulse and more ...) https://720kb.github.io/angular-fx
Stars: ✭ 181 (+248.08%)
Mutual labels:  angular-directives

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>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].