Javascript 图像不';从服务器获取时不显示

Javascript 图像不';从服务器获取时不显示,javascript,angularjs,image,Javascript,Angularjs,Image,我从服务器读取图像url,但它的名称对于所有用户都是相同的。 前 当我想显示图像时,我将图像源设置为上面的url,但直到我单击页面中的某个位置,图像才显示出来。我想问题在于角度摘要,但我尝试了$scope.$apply()和$scope.$digest(),但没有帮助 我这样设置url $scope.imageSource = CONSTS.userAvatar.replace('$1', $scope.userID) + "?n=" + Math.random(); 有什么建议吗 编辑 &l

我从服务器读取图像url,但它的名称对于所有用户都是相同的。 前

当我想显示图像时,我将图像源设置为上面的url,但直到我单击页面中的某个位置,图像才显示出来。我想问题在于角度摘要,但我尝试了$scope.$apply()和$scope.$digest(),但没有帮助

我这样设置url

$scope.imageSource = CONSTS.userAvatar.replace('$1', $scope.userID) + "?n=" + Math.random();
有什么建议吗

编辑

<img id="avatarImage" ng-src="{{imageSource}}" ng-mouseover="showDelete=true;" onerror="angular.element(document.getElementById('avatarImage')).scope().avatarDoesntExist()" onload="angular.element(document.getElementById('avatarImage')).scope().avatarExist()"  ng-mouseleave="showDelete=false;" class="thumbnail" style='margin-right: 7px;margin-top: 7px;margin-bottom: 7px;width: 100%;'/>                    


我有两种方法(“onload”/“onerror”),因为文件夹中可能有化身图像,也可能没有。如果头像文件夹中没有任何图像,我会用浏览按钮显示框,如果用户有头像图像,我会用图像显示框,用浏览按钮隐藏框

在帖子中添加代码,以显示如何将
imageSource
设置为图像。希望您使用的是
ngsrc
?我尝试了ngsrc,但它不起作用。您什么时候设置图像源?你说“当我想显示图像时”,这是否意味着你正在调用某种事件来设置图像?你能把你的标记代码放在这里吗?请看编辑后的文章。我发布了图像html标签。