Skip to content Skip to sidebar Skip to footer

Angularjs Doesn't Update Img Src When Model Changes

I use ng-src to load images. Value is loaded from some scope variable, like this: My issue is that when I run delete $scope.currentR

Solution 1:

This is the expected behaviour from the ngSrc and ngHref directives. These directives only support recognising new paths, but when path is not available, the directives will exit silently (I see a pull request here.).

So a possible workaround could be to use ngShow along with the ngHref to hide the tag altogether when image variable is not available anymore:

<imgng-href="{{currentReceipt.image}}"ng-show="currentReceipt.image" />

Solution 2:

call $scope.$apply() after delete $scope.currentReceipt.

Solution 3:

The following solution works for me:

<imgng-src="{{currentReceipt.image}}"ng-show="currentReceipt.image != null" />

Solution 4:

You can actually check for length and do

 <img ng-show="user.thumbnail.length > 1"class="img-circle thumb pull-left" ng-src="{{user.thumbnail}}" alt="{{user.firstname}} {{user.lastname}}">

Post a Comment for "Angularjs Doesn't Update Img Src When Model Changes"