Skip to content

Instantly share code, notes, and snippets.

@cozzbie
Last active October 17, 2019 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cozzbie/04725b332eaebb67c2c06fa282827af4 to your computer and use it in GitHub Desktop.
Save cozzbie/04725b332eaebb67c2c06fa282827af4 to your computer and use it in GitHub Desktop.
import { Directive, Input, HostBinding } from '@angular/core';
@Directive({
selector: 'img[appImageFallback]'
})
export class ImageFallbackDirective {
fallback = 'path/to/default/image.png';
@Input() src: string;
constructor() {}
@HostBinding('attr.src') get source() {
return this.src || this.fallback;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment