我使用ng-src
加载图像。值从一些范围变装,像这样:当模型更改时,AngularJS不更新img src
<img ng-src="{{currentReceipt.image}}"/>
我的问题是,当我运行delete $scope.currentReceipt
,它使ng-src
属性为空,但在src
属性不反映它。因此,我不断看到那个图像,我需要空的占位符。
我该如何处理?
我使用ng-src
加载图像。值从一些范围变装,像这样:当模型更改时,AngularJS不更新img src
<img ng-src="{{currentReceipt.image}}"/>
我的问题是,当我运行delete $scope.currentReceipt
,它使ng-src
属性为空,但在src
属性不反映它。因此,我不断看到那个图像,我需要空的占位符。
我该如何处理?
这是ngSrc和ngHref指令的预期行为。这些指令只支持识别新路径,但是当路径不可用时,指令将会是exit silently(我在这里看到一个拉取请求)。
因此,一个可能的解决方法可以是使用ngShow与ngHref一起完全隐藏标记时图像变量不再可用。
<img ng-href="{{currentReceipt.image}}" ng-show="currentReceipt.image" />
调用$范围$适用()之后删除$范围。 currentReceipt。
以下解决方案适用于我:
<img ng-src="{{currentReceipt.image}}" ng-show="currentReceipt.image != null" />
实际上,你可以检查长度并做
<img ng-show="user.thumbnail.length > 1" class="img-circle thumb pull-left" ng-src="{{user.thumbnail}}" alt="{{user.firstname}} {{user.lastname}}">
放入的plunkr –
可能的复制[空NG-SRC不更新图片](http://stackoverflow.com/questions/22092687/empty-ng-src-doesnt-update-image) –