ngx-broken-img
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

ngx-broken-img

npm

Angular 2+ directive to fix broken url in img.
If image url returns 404 a placeholder is used to fill img's src.

Demo

https://stackblitz.com/edit/ngx-broken-img

Install

npm

npm install ngx-broken-img --save

yarn

yarn add ngx-broken-img

Setup

step 1: add NgxBrokenImgModule to app NgModule

import { CommonModule } from '@angular/common';
import { NgxBrokenImgModule } from 'ngx-broken-img';

@NgModule({
  imports: [
    CommonModule,
    NgxBrokenImgModule,
  ],
  bootstrap: [App],
  declarations: [App],
})
class MainModule {}

Use

<!-- Default placeholder -->
<img src="http://somebrokenurl" ngxBrokenImage>

<!-- Custom base64 placeholder -->
<img src="http://somebrokenurl" ngxBrokenImage="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mM88x8AAp0BzdNtlUkAAAAASUVORK5CYII="> 

Package Sidebar

Install

npm i ngx-broken-img

Weekly Downloads

3

Version

1.2.0

License

MIT

Unpacked Size

44.7 kB

Total Files

12

Last publish

Collaborators

  • andreagrossetti