Last active
October 17, 2019 00:51
-
-
Save cozzbie/04725b332eaebb67c2c06fa282827af4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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