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

查看:131
本文介绍了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}}"/>

我的问题是,当我运行删除$ 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天全站免登陆