Last active
April 25, 2019 21:05
-
-
Save d0rsha/1536685e229c613cea167788b981f3e3 to your computer and use it in GitHub Desktop.
[getImageURL] Observable #firebase
This file contains 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
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