You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
ngSrc does not update the src attribute if the value is blank:
attr.$observe(normalized, function(value) {
if (!value) { // do not update ngSrc or ngSrcSet if blank
if (attrName === 'href') {
attr.$set(name, null);
}
return;
}
I noticed this when answering this question on stackoverflow to create a directive to display an alternate image if there is an error loading the bound image url.
This seems inappropriate to me. Imagine a SPA that loads a new product using $http. If the new product has a blank string for the image URL, the page would continue to display the image for the previous product when even an error placeholder for image not found would be more appropriate. Is there some special reason that the src attribute should not be set to blank when the bound url is empty? If not, I think it should be changed to appropriately reflect the intended binding.
The text was updated successfully, but these errors were encountered:
I seem to recall that there was a PR or bug filed about this in the past, let me see if I can find it --- I can't recall what the decision was about this.
Originally, ngSrc/ngHref would be set to an emty value if that was the result of the interpolation.
Then, it was reported that some browsers make a request to the current page when the see an empty src attribute, so the behaviour was changed in order not to change the value of the attribute if the interpolation resulted in an empty string: b6e4a71
Later, it was decided that, with href, it was preferrable to remove the attribute (instead of leaving the previous value), because the user could interact with the element and get wrong behaviour. So, it was changed to remove the href attribute when ngHrefgets evaluated to an empty string: 469ea33
Basically, I don't see why we shouldn't remove the src attribute in the same fashion.
Furthermore, with href I would prefer to not remove it and set it to an empty string instead (because some browsers will decorate an <a> element as a link only if it has an href attribute (even an empty one)).
So, this is my suggestion:
attr.$observe(normalized, function(value) {
if (!value && (attrName !== 'href')) {
attr.$set(name, null); // remove ngSrc or ngSrcset if blank
return;
}
...
When I updated ngHref to remove the href attribute I originally did the same to ngSrc, but @caitp was against it since she was worried it might result in some FOUC behavior, so we decided on leaving ngSrc as it was. See the discussion in #6986.
It is definitely possible, but rather improbable. At least I can't think of a sane use-case, where one might set ngSrc to some non-empty value, then set it to empty and quickly to non-empty again.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
ngSrc does not update the src attribute if the value is blank:
I noticed this when answering this question on stackoverflow to create a directive to display an alternate image if there is an error loading the bound image url.
This seems inappropriate to me. Imagine a SPA that loads a new product using $http. If the new product has a blank string for the image URL, the page would continue to display the image for the previous product when even an error placeholder for image not found would be more appropriate. Is there some special reason that the src attribute should not be set to blank when the bound url is empty? If not, I think it should be changed to appropriately reflect the intended binding.
The text was updated successfully, but these errors were encountered: