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

fix for style attribute not being copied to the dst object #4882

Closed
wants to merge 1 commit into from

Conversation

jcompagner
Copy link

When we move to 1.2 we got a lot of exceptions in the console:

TypeError: Cannot read property 'length' of undefined
at $interpolate (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:7960:24)
at attrInterpolatePreLinkFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:6354:33)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:6429:44
at nodeLinkFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:6068:13)
at compositeLinkFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:5509:15)
at nodeLinkFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:6082:24)
at compositeLinkFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:5521:15)
at compositeLinkFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:5524:13)
at publicLinkFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:5421:30)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:1287:27

(and a lot more, exactly like that)

this is because angular expects that the attributes object has a "style" attribute by that name.
But angular doesn't copy that style tag to the dst map in the compile.js code (mergeTemplateAttributes function)

We have for example a directive called that doesn't have the "style" attribute (it just have some others)
then the template of that directive does have a "style" tag in the first dom element.
Now angular wants to merge all the attributes in each other. But for the style tag it seems to do something totally different then by other attributes (or even the class which also has a special copy)

I made a plunker to show the problem also:
http://plnkr.co/edit/OdFWJCmlPijE7LIOumAM?p=preview

@ghost ghost assigned tbosch Nov 12, 2013
@tbosch
Copy link
Contributor

tbosch commented Nov 12, 2013

Thanks.
I could reproduce the problem and it only happens when all of the below is true:

  • directive with replace:true
  • directive with template
  • template uses a style attribute with interpolation ({{...}})
  • no style attribute on the element that uses the directive

Here is a reduced case: http://plnkr.co/edit/Haplv16k6eHh5O5PJphc?p=preview

@jcompagner
Copy link
Author

Tobias,

you can have the credits, i don't mind ;)
its just 1 single addition then (if the line shouldn't be deleted)

So it will be just quicker to put in under your name, (and also make the test case, i think you are better suited for that then me)

I did sign the cla so that if there are bigger patches or contributions coming up i am ready.

By the way, we are building a generic webcomponent beans and all our beans do have exactly those 4 points, so 1.2 really broke pretty much everything ;)

@tbosch
Copy link
Contributor

tbosch commented Nov 12, 2013

Ok, created a new PR. Thanks for signing the CLA and reporting this!

Sounds like you are building a UI builder. Is it open source?

tbosch added a commit to tbosch/angular.js that referenced this pull request Nov 13, 2013
A directive with a template with `replace: true` and an interpolated style at the root element should work correctly.

Closes angular#4882.
@tbosch
Copy link
Contributor

tbosch commented Nov 13, 2013

Hi,
just found out that interpolating style attributes does not work in IE<11! (e.g. style="height: '{{1+1}}px'@).
If you have that problem, use ng-style instead. The bug reported in this issue is still valid for other browsers.

Tobias

@tbosch tbosch closed this in e1254b2 Nov 13, 2013
@tbosch
Copy link
Contributor

tbosch commented Nov 13, 2013

Changes landed in master as e1254b2,

@jcompagner
Copy link
Author

The editor (and later on the client) are open source:
https://www.servoyforge.net/projects/servoy/repository/show/branches/html_formeditor_branch

@tbosch
Copy link
Contributor

tbosch commented Nov 13, 2013

That's great. Is there a running demo / download?

jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
A directive with a template with `replace: true` and an interpolated style at the root element should work correctly.

Closes angular#4882.
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
A directive with a template with `replace: true` and an interpolated style at the root element should work correctly.

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

Successfully merging this pull request may close these issues.

2 participants