2

Context of the question:

I'm using the solution from this question: How to update AngularJS view when the value has not changed? So in my view I have:

 <img ng-src="{{user.photo.pathRelative}}{{randomStr}}" alt=""/>

when I change the photo I run the following code in my contoller:

 $scope.user.photo.pathRelative = somePathToPhoto;
 $scope.randomStr  = '?randomStr=' +  new Date().getTime();

This results in the following html (and everyting works as it should):

<img ng-src="img/profiles/5350f142dd9624b818d90007/5350f142dd9624b818d90007.png?randomStr=1398159116845" alt="" src="img/profiles/5350f142dd9624b818d90007/5350f142dd9624b818d90007.png?randomStr=1398159116845">

Question:

Now I want to allow user to delete this photo, so when he hits the delete button I do:

 $scope.user.photo.pathRelative = '';
 $scope.randomStr  = '';

However, this results in the following html:

<img ng-src="" alt="" src="?randomStr=1398159116845">

So src attribute is still set, hence the browers tries to render it but obviously the path is not valid.

Any hints why this src is set to incorrect value?

Community
  • 1
  • 1
Jakub
  • 3,129
  • 8
  • 44
  • 63

2 Answers2

4

You could set up ng-if to get rid of the img element in case the path is not set.

Juho Vepsäläinen
  • 26,573
  • 12
  • 79
  • 105
0

This is a known issue (actually this is by design). See this link and a workaround.

Community
  • 1
  • 1
zszep
  • 4,450
  • 4
  • 38
  • 58