0

私はストレートFirebaseのドキュメントからこのコードを持っている:FirebaseのストレージからイメージのURLを取得する方法は?

// Create a reference to the file we want to download 
    var user = firebase.auth().currentUser.uid; 
    var storageRef = firebase.storage(); 
    var pathReference = storageRef.ref('/' + user + '/profilePicture/' + image.name); 

    //var starsRef = storageRef.child('/' + user + '/profilePicture/' + file.name); 

    // Get the download URL 
    pathReference.getDownloadURL().then(function(url) { 
    // Insert url into an <img> tag to "download" 
     $scope.imageUrl = url; 
     console.log($scope.imageUrl); 
    }); 

しかし、私は示す画像...任意の助けを得るために私のhtmlファイルに書き込むために何を把握することはできませんか?

答えて

1

結果をコントローラの変数とHTMLのng-srcに入れてください。

サービスを使用してURLを取得し、コントローラで直接取得するのではなく、

コントローラ

app.controller('MyController', ['$scope', function($scope) { 
    // Create a reference to the file we want to download 
    var user = firebase.auth().currentUser.uid; 
    var starsRef = storageRef.child('/' + user + '/profilePicture/' + file.name); 

    // Get the download URL 
    starsRef.getDownloadURL().then(function(url) { 
    // Insert url into an <img> tag to "download" 
     $scope.imageUrl = url; 
    }); 
}]); 

HTML

<img ng-src="{{imageUrl}}"/> 
+0

こんにちは、あなたの助けをありがとう、それは私の絵の周りのCSSを表示するが、絵自体は**ありません**表示中(まだ)。 imageUrlでconsole.logを試してみたところ、nothingsも表示されます。何が原因だろうか? – FrenchyNYC

+0

デバッグしようとしているのは、imageUrlではなく 'console.log(url)'です。 imageUrlをデバッグしたい場合は、 'console.log($ scope.imageUrl)'を実行してください。 – e666

+0

私はストレージを参照するのを忘れていました。今私が最後の問題は、 "ファイル"が定義されていないということです。どのように私はこのデータを持つことができますか? それ以外はすべて動作します;) – FrenchyNYC

関連する問題