ngx-broken-img

July 15, 2026 ยท View on GitHub

npm

Angular 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

Compatibility

Pick the release that matches your Angular version. From v21 onward the library's major version tracks the Angular major it targets.

ngx-broken-imgAngular
22.x22
21.x21
1.3.x20
1.2.x17
1.1.x13

Install

npm

npm install ngx-broken-img --save        # latest (Angular 22)
npm install ngx-broken-img@21 --save     # Angular 21

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" ngxBrokenImg>

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