Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
ng2-img-fallback
Advanced tools
Load placeholder image on image error
Angular 2 directive that loads placeholder image on primary image error.
npm install ng2-img-fallback --save
In case you're using SystemJS
see configuration here
Add module to your module's imports
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app';
import { Ng2ImgFallbackModule } from 'ng2-img-fallback';
@NgModule({
imports: [BrowserModule, Ng2ImgFallbackModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
Use it in you component
import { Component } from '@angular/core';
@Component({
selector: 'example-app',
template: '<img src="some_img.png" src-fallback="{{ placeholder }}">'
})
export class AppComponent {
placeholder = 'http://placehold.it/200x200';
}
(loaded)
ng2-img-fallback
provides (loaded)
event which is fired when either src
or src-fallback
is loaded.
To determinate whether original source or fallback is loaded - add a param to your callback for the (loaded)
event.
Example:
First add callback to your component
onLoaded(isFallback: boolean) {
// make somthing based on 'isFallback'
}
and then bind it to the loaded
event
<img src="picture1.png" src-fallback="picture2.png" (loaded)="onLoaded($event)">
FAQs
Angular2 directive for image fallback
We found that ng2-img-fallback demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.