Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Reseting a ng-src value #1218

escalant3 opened this Issue · 9 comments

8 participants


When setting a ng-src to '' to clean its value does not work in Chrome. It does work in Firefox. Here is the jsfiddle:


I am not sure that this is really an angular bug.

The latest versions of chrome and firefox both seem to behave the same in this regard (the image doesn't change when it's src is set to '' or undefined. Indeed, the W3C spec states:

The src attribute must be present, and must contain a valid non-empty URL potentially surrounded by spaces referencing a non-interactive, optionally animated, image resource that is neither paged nor scripted.

So the fact that setting ng-src to '' gives odd/differing behaviour in different browsers isn't really a bug in angular.

@escala if you agree can you close this issue please? Trying to do a clear out :smile:


@escalant3 escalant3 closed this

I'm seeing this issue also. I think this is a valid bug. There are always quirks and differences between browsers. How many exceptions and workarounds are there in Angular to support IE? If there is a possible work around in Chrome to make this function as expected, then maybe it could be considered for a fix.


@kkartch - what do you suggest as a fix?


I am actually seeing something different from escalant3 because I'm seeing this in Firefox also, so maybe it isn't a Chrome specific bug. The reason it isn't clearing the image in the directive is because of the following if statement in the $observe callback:

          if (!value)

          attr.$set(attrName, value);

It returns before the attr.$set, so the empty string value never gets set on the src attribute. I'm sure that if statement is there for a reason, so I'm not sure what would be broken if that was taken out. !value can evaluate to true for quite a few reasons, and maybe empty string was not intended to evaluate true in this case?

This might not be the best fix, but I think this would work:

          if (!value && value !== "")

          attr.$set(attrName, value);

@kkartch the check for empty src attributes was added in b6e4a71 to prevent problems with empty src attributes. And there are plenty of possible problems, check the mentioned commit comment plus this article:

Not to mention that HTML5 specification states:

src = non-empty URL potentially surrounded by spaces

"Support" for empty src attributes can be harmful and this is browser-implementation dependent.


i fix it by set value = " ";
with whitespace.
and it's work.


@jSemyonom Worked great! Thanks for the tip!


w3c: A URL that is not the empty string, optionally with leading and/or trailing space characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.