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

ng-src

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-src

Small angular directive to load images with XHR and expose the request

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

NPM

NgSrc

Small Angular directive that loads images using XHR and exposes the request.

Usefull for cases when we need to get additional information like headers set by the server.

The image is requested from the server as arraybuffer and a blob is created from the response. A local url is created with createObjectURL and this is set as src for the image tag.

Installing

Use npm or yarn to install

npm install ng-src --save

or

yarn add ng-src --prod

Using

Import NgSrcModule and add it to the imports array of your app module

import { NgSrcModule } from 'ng-src';

@NgModule({
  imports: [
    NgSrcModule,
  ],
})
export class AppModule { }

You now can use the ngSrc directive on image tags inside your application

 <img [ngSrc]="'http://localhost:4200/demo/assets/cat300.jpg'"
      (ngOnLoad)="exampleCallback($event)">

The directive exposes ngOnLoad event that is triggered when the image is loaded and gets as argument the XMLHttpRequest object. One can use this to get any additional information required like the headers

  exampleCallback(request: XMLHttpRequest) {
    console.log(request.getAllResponseHeaders());
  }

Contributing

Clone this repository

git clone https://github.com/adrianfaciu/ngsrc

And install all dependencies

yarn install

or

npm install

Source code is inside src/ng-src and a demo application is found inside src/demo.

Scripts

  • build:lib - build and bundle the lib package using ng-packar
  • serve:demo - serve the demo application
  • test - execute the tests
  • e2e - execute end to end tests
  • lint - run the linter on the source code

All these scripts can be used with npm run scriptName or yarn scriptName.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Adrian Faciu - Initial work

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

FAQs

Package last updated on 05 Nov 2017

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