范围图片网址未更新&在视图中显示(AngularJS)

时间:2016-10-20 07:47:10

标签: javascript angularjs firebase firebase-storage

我是AngularJS的新手,我试图从Google Firebase中检索放在范围变量中的图片链接。当我在加载它之前使用不同的控制器执行URL中的URL检索时,这种方法很有效。但是,当在此控制器中检索它时,我的div不知何故不想显示图像。我已经使用简单的ng-bind检查了范围变量是否已更新,并且确实如此。但是,视图中的图片div保持为空。有谁知道如何让我的视图显示图像?

控制器:

$scope.profilepicture = null;

var storageRef = firebase.storage().ref();
var path = "profilepictures/" + userFactory.getUser().uid + "/profilepicture";
var profilePicRef = storageRef.child(path);

profilePicRef.getDownloadURL().then(function(url) {
    $scope.$apply(function(){
        $scope.profilepicture = url;
    });
}).catch(function(error) {
});

查看:

<div ng-click="getImage()" ng-style="{'background-image' : 'url({{profilepicture}})'}" style="width:100px; etc...></div>

2 个答案:

答案 0 :(得分:1)

ng-style="{'background-image' : 'url(' + profilepicture + ')'}"

我刚发现了这个问题。 ng风格的网址需要像这样写:&#39; +值+&#39;

感谢您的帮助:)

答案 1 :(得分:0)

通过从那里删除大括号来尝试这样做,但只需确保获得正确的profilepicture值。

<div ng-click="getImage()" ng-style="{'background-image' : 'url(profilepicture)'}" style="width:100px; etc...></div>
相关问题