# ng-lazy-image

> Simple and lightweight lazy load images directive for Angular 2+

Latest version **1.0.5** (published 2020-09-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install ng-lazy-image
pnpm add ng-lazy-image
yarn add ng-lazy-image
bun add ng-lazy-image
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2020-09-01 |
| First published | 2020-08-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 99.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Luong Van Phuc |
| Maintainers | phucluong |
| Keywords | lazy-loading images, lazy load images, native lazy loading, Intersection Observable API, lazy load background images |

## Links

- npm: https://www.npmjs.com/package/ng-lazy-image
- Repository: https://github.com/luongvanphuc/ng-lazy-image
- Issues: https://github.com/luongvanphuc/ng-lazy-image/issues
- npm.io page: https://npm.io/package/ng-lazy-image

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^1.10.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2020-09-01
- 1.0.4 — 2020-08-28
- 1.0.3 — 2020-08-24
- 1.0.2 — 2020-08-24
- 1.0.1 — 2020-08-23
- 1.0.0 — 2020-08-13

## README

# Simple and lightweight lazy-loading images library for Angular 2+.
This library focus only in lazy-load the images job to make it simple and lightweight as promise, you should handle the styles by yourself.

## Lazy-load Approach

* For images using `<img>` tag, it will check if the browser supports lazy-loading natively (`loading="lazy"`). If it does, let the browser does the job. If it doesn't, it will fallback to Intersection Observable API.

* For background images using `<div>` tag, it will use the Intersection Observable API approach.

## Install

To install the package, just run:

```
$ npm install ng-lazy-image
```

or the following if you are using yarn:

```
$ yarn add ng-lazy-image
```

## Setup

Import the library in your module (eg: app.module.ts)):

``` ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { LazyImageModule } from 'ng-lazy-image'; // import the lib here
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    LazyLoadImageModule, // include the lib into the module
  ],
  bootstrap: [AppComponent],
})
export class AppModule { }
```

Usage:

``` html
<!-- For image -->
<img data-src="https://images.unsplash.com/photo-1495954484750-af469f2f9be5?w=753&q=80" loading="lazy">

<!-- For background image -->
<div data-src="https://images.unsplash.com/photo-1473186578172-c141e6798cf4?w=753&q=80" loading="lazy"></div>
```

---
_Source: https://npm.io/package/ng-lazy-image · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
