Skip to content

Instantly share code, notes, and snippets.

@d0rsha
Last active April 25, 2019 21:05
Show Gist options
  • Save d0rsha/1536685e229c613cea167788b981f3e3 to your computer and use it in GitHub Desktop.
Save d0rsha/1536685e229c613cea167788b981f3e3 to your computer and use it in GitHub Desktop.
[getImageURL] Observable #firebase
imageObservables = {};
getImageUrl(ref: string) {
if (!ref) { return; }
const regEx: RegExp = /^[0-9]/;
if (!regEx.test(ref.charAt(0))) { return; }
if (ref in this.imageObservables) {
return this.imageObservables[ref];
} else {
this.imageObservables[ref] = this.storageService.getMenuPicUrl(ref);
return this.imageObservables[ref];
}
}
/* ...html
<img [src]="getImageUrl('fileName.png') | async">
<img src="{(getImageUrl('fileName.png') | async)}">
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment