AngularJS doesn't update img src when model changes

前端 未结 4 650
面向向阳花
面向向阳花 2020-12-14 21:09

I use ng-src to load images. Value is loaded from some scope variable, like this:


相关标签:
4条回答
  • 2020-12-14 21:30

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

    0 讨论(0)
  • 2020-12-14 21:39

    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:

    <img ng-href="{{currentReceipt.image}}" ng-show="currentReceipt.image" />
    
    0 讨论(0)
  • 2020-12-14 21:46

    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}}">
    
    0 讨论(0)
  • 2020-12-14 21:51

    The following solution works for me:

    <img ng-src="{{currentReceipt.image}}" ng-show="currentReceipt.image != null" />
    
    0 讨论(0)
提交回复
热议问题