Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Remove browser sniff in attrs.js #15611

Open
@david-mark

Description

@david-mark

Note: for support questions, please use one of these channels: https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#question. This repository's issues are reserved for feature requests and bug reports.

Do you want to request a feature or report a bug?

Neither.

What is the current behavior?

Depends on browser and configuration. Relies on browser sniffing. May "work" by coincidence in all supported browsers, but could fail in future.

Either use a feature test for this or simply set the property if the attribute is missing, regardless of what browser we think it is. Certainly no harm will come from that. Also not sure why prop is used instead of just setting the property.

if (propName) element[propName] = attr[name];

For all we know some non-IE browser version may come out tomorrow and demonstrate the same bug.

http://jibbering.com/faq/notes/detect-browser/

// Support: IE 9-11 only
// On IE, if "ng:src" directive declaration is used and "src" attribute doesn't exist
// then calling element.setAttribute('src', 'foo') doesn't do anything, so we need
// to set the property as well to achieve the desired effect.
// We use attr[attrName] value since $set can sanitize the url.
if (msie && propName) element.prop(propName, attr[name]);

Test would be something like:

var elDummyImage = document.createElement('img');
document.body.appendChild(elDummyImage);
elDummyImage.setAttribute('src', 'test');

var problemSettingImgAttribute =  elDummyImage.src === '';

document.body.removeChild(elDummyImage);

Then make a direct inference based on the test result:

if (propName && problemSettingImgAttribute) element[propName] = attr[name];

Not sure why we aren't just setting the property in the first place. Will certainly cause the IMG to sprout a SRC attribute.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions