我直接从Firebase的文档中获得以下代码:

// 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文件中写些什么才能得到显示...的图像,有什么帮助吗?

最佳答案

只需将结果放入控制器的变量中,并放在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}}"/>

10-04 22:08
查看更多