当模型更改时,AngularJS 不会更新 img src [英] AngularJS doesn't update img src when model changes

查看:28
本文介绍了当模型更改时,AngularJS 不会更新 img src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ng-src 加载图像.值是从某个范围变量加载的,如下所示:

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

<img ng-src="{{currentReceipt.image}}"/>

我的问题是,当我运行 delete $scope.currentReceipt 时,它会使 ng-src 属性为空,但不会在 src 中反映出来代码>属性.因此,我不断看到需要空占位符的图像.

My issue is that when I run delete $scope.currentReceipt, it makes ng-src attribute empty but doesn't reflect it in src attribute. So as a result I keep seeing that image where I need empty placeholder.

我该如何处理?

推荐答案

这是 ngSrc 和 ngHref 指令的预期行为.这些指令仅支持识别新路径,但当路径不可用时,指令将 静默退出(我在这里看到一个拉取请求.

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.).

因此,当图像变量不再可用时,可能的解决方法是使用 ngShow 和 ngHref 来完全隐藏标签:

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" />

这篇关于当模型更改时,AngularJS 不会更新 img src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆