私の角型アプリケーションでng-repeatリストのng-srcを評価するために使用するこの関数を書いています。関数を呼び出すたびに値が正しいように、呼び出しを同期させる必要があります。問題は次のとおりです。FirebaseストレージからダウンロードURLを返す関数
は、なぜこのコードは値を返さない:
var storage = firebase.storage();
var returnVal; //causes sync issues
var getImageUrl = function (time) {
storage.ref('images/' + time + '.jpg').getDownloadURL().then(function (url) {
returnVal = url;
});
return returnVal;
};
しかし、これは動作しません:
var storage = firebase.storage();
var getImageUrl = function (time) {
var returnVal; //so that this is specific to the function
storage.ref('images/' + time + '.jpg').getDownloadURL().then(function (url) {
returnVal = url; //I simply want to return the value of 'url'
});
return returnVal;
};
私はgetImageUrl()関数が返すことができますどのように任意のアイデア.thenからのURL?
これは、ドキュメントのリンクです:結局私はこれに似て使用するために$スコープ機能にこれを有効にしますhttps://firebase.google.com/docs/storage/web/download-files
:
<div ng-repeat="message in messages">
<img ng-src="{{ getImageUrl(message.time) }}">
</div>
も参照してくださいhttps://stackoverflow.com/questions/42956250/get-download-url-from-file-uploaded-with-cloud -functions-for-firebase – Kato