Created
May 28, 2018 08:38
-
-
Save realtomaszkula/6a67dafb3af4c0f9ce5a954327a1b91a 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
@Directive({ | |
selector: 'img[appProgressiveImage]', | |
providers: [{ | |
provide: Dimensions, | |
useExisting: forwardRef(() => ProgressiveImageDirective) | |
}] | |
}) | |
export class ProgressiveImageDirective implements OnInit, Dimensions { | |
@HostBinding('style.width.px') | |
width: number; | |
@HostBinding('style.height.px') | |
height: number; | |
private _src: string; | |
@HostBinding('attr.src') | |
@Input() | |
set src(src: string) { | |
this.imageState.emitLoading(); | |
this._src = src; | |
} | |
get src() { | |
return this._src; | |
} | |
@HostListener('load') | |
onLoad() { | |
this.imageState.emitLoaded(); | |
} | |
@HostListener('error') | |
onError() { | |
this.imageState.emitError(); | |
} | |
constructor(private imageState: ImageStateService) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment