Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-default-image

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-default-image

Angular library which provides a way prevend image rendering when the image loading failed with custom replacement image and provide extracted meta info from the image.

  • 0.2.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

ngx-default-image (latest)

ngx-default-image npm version ngx-default-image

  • Angular library which provides a way prevend image rendering when the image loading failed with custom replacement image.

  • Get extracted meta info from the image.




Import

Import the module on your app.module.ts file as follow.

import { NgxDefaultImageModule} from "ngx-default-image";

Add to imports

imports: [
  ...
  NgxDefaultImageModule
  ...
],

Using META interface

import { META } from "ngx-default-image";

Core function

<img src="'https://dummyimage.com/600x400/fff/000'" 
[imageURL]="imageURL" NgxDefaultImage />
  • imageURL : Replacement image URL (Usually from asset folder in any dimension).

Using service

Emit the function in order to get meta info as follows.

<img src="'https://dummyimage.com/600x400/fff/000'" 
[imageURL]="imageURL" (imageMetaInfo)="imageMetaInfo($event)" 
NgxDefaultImage />
import { META } from "ngx-default-image";
public imageMeta: META;
public imageURL = "https://cdn-icons-png.flaticon.com/128/1829/1829412.png"; // Fallback URL
public imageMetaInfo(event: META) {
  this.imageMeta = event;
  consoloe.log(this.imageMeta);
}

For series of image under loop

<div *ngFor="let img of images:let index = index;">
  <img src="'https://dummyimage.com/600x400/fff/000'" 
  [imageURL]="imageURL" 
  (imageMetaInfo)="imageMetaInfo($event, index)" 
  NgxDefaultImage />
</div>
public imageMetaInfo(event: META, index: number) {
  consoloe.log(`Meta info of image at ${index} is ${event}.`);
}

Ability

The image will return the meta info as follows:

public imageMetaInfo(event: META) {
  this.imageMeta = event;
}

Meta properties

PropertiesData Type
isValidImageBoolean
aspectRatiostring
xnumber
ynumber
rwidthnumber
rheightnumber
renderTimestring
topnumber
rightnumber
bottomnumber
leftnumber
datedOnany
widthnumber
heightnumber
srcstring
esrcstring
altstring
crossoriginstring

Code integration

To use this package as a service npm i ngx-default-image install this on the root angular project .

Note: Don't forget to run this commend npm i ngx-default-image on root folder or else it will throw error.

Then import the module as follow on imports array

NgxDefaultImageModule


Keywords

FAQs

Package last updated on 01 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc