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

Preserve attributes camelcased #9845

Closed
Mouvedia opened this issue Oct 30, 2014 · 5 comments
Closed

Preserve attributes camelcased #9845

Mouvedia opened this issue Oct 30, 2014 · 5 comments

Comments

@Mouvedia
Copy link

cf http://stackoverflow.com/questions/24910730/how-to-handle-patterntransform-using-ng-attr-keep-it-camelcased

In short Id like ng-attr-patternTransform to produce patternTransform (instead of patterntransform currently).
It's a common problem if you are dealing with svg elements.

The viewBox attribute is another common case.

@caitp
Copy link
Contributor

caitp commented Oct 30, 2014

this is a reasonable request, I think. The thing is that it makes it really hard to normalize the attribute name.

@caitp
Copy link
Contributor

caitp commented Oct 30, 2014

I don't think it should break any apps though, it's just another step towards "first class SVG elements", and HTML attributes are case insensitive anyways, so it should be okay.

@Mouvedia
Copy link
Author

Looking at this page, it makes you realize how many attributes are affected.

@wesleycho
Copy link
Contributor

One solution could be to store a hash of attributes with key-value pairs being [svg attribute lowercase]: [svg attribute correct cased], and to check if the string is prefixed against that hash. If the value is defined, then the casing could be preserved - it seems that whenever ng-attr is present, the browser interprets it as a regular HTML attribute and thus reads it as a case insensitive name.

Here is a simple plunker that outputs the object you can use to inspect with: http://plnkr.co/edit/sn2IsH0d9fP0jbK7VP4X?p=preview .

The attributes object on the DOM node can be used to find the case insensitive version of the attribute.

@IgorMinar
Copy link
Contributor

as discussed, we can just have an encoding scheme for ngAttr and use for example underscore to denote camelcasing.

so ng-attr-pattern_transform="foo" would create a binding for patternTransform attribute.

@IgorMinar IgorMinar modified the milestones: ng-fixit #1, Backlog Nov 22, 2014
petebacondarwin pushed a commit that referenced this issue Dec 9, 2014
SVG attributes are case sensitive and some have upper case letters in them
This change ensures that we can identify these, when being used with the `ng-attr`
directive, by encoding upper case letters with a preceding underscore.

For example to apply `ng-attr` to the `viewBox` attribute we could write
`ng-attr-view_box` - or any of the other variants: `ng:attr:view_box`,
`data-ng-attr-view_box`, etc.

Closes #9845
Closes #10194
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants