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

Inconsistent angular.element.scope() behaviour when using templateUrl in directive #5099

Closed
artur-charcenko opened this issue Nov 23, 2013 · 4 comments

Comments

@artur-charcenko
Copy link

Here's the example that demonstrates the issue. Scope ids should not match. However it works when using inline template.
It also works correctly when using jQuery v1.10.2 and templateUrl.

@ghost ghost assigned matsko and caitp Dec 31, 2013
@caitp
Copy link
Contributor

caitp commented Jan 7, 2014

This seems to work as expected (without jQuery) with 1.2.8. But with newer versions of jQuery it seems to be an issue.

with snapshot, no jQuery

Seems like it relates to jQuery's expandostore, and I'm not sure it's a good idea to hack around it, although it is unfortunate.

I can look into a way to do this, but it might take some time. Maybe it would be worth getting the jQuery team looking at it, or something.

@caitp
Copy link
Contributor

caitp commented Jan 9, 2014

On this line,

linkFn(linkFn.isolateScope ? isolateScope : scope, $element, attrs,
, linkFn gets called with the correct scope passed in, but the element passed in does not have the correct scope.

This seems to be coming from the replaceWith function in the HTML compiler at

replaceWith($rootElement, $compileNode, compileNode);
--- the original $compileNode has the data added, but after the replacement it doesn't.

So this seems like a bug with replaceWith, I'm seeing if I can get some guidance from jQuery people on what to do about that

caitp added a commit to caitp/angular.js that referenced this issue Jan 9, 2014
Before this patch, with modern versions of jQuery being used, the
element data cache was not being copied over into the new element
when replacing an asynchronous directive's compile node with its
template. This caused an issue where the element passed into a
post link function's scope() method would return the incorrect
scope.

The test which is added passes regardless of the change in jQuery
1.10.2, which is currently checked into the tree, but fails without
the change in jQuery 2.0.3.

Fixes angular#5099
caitp added a commit to caitp/angular.js that referenced this issue Jan 9, 2014
Before this patch, with modern versions of jQuery being used, the
element data cache was not being copied over into the new element
when replacing an asynchronous directive's compile node with its
template. This caused an issue where the element passed into a
post link function's scope() method would return the incorrect
scope.

The test which is added passes regardless of the change in jQuery
1.10.2, which is currently checked into the tree, but fails without
the change in jQuery 2.0.3.

Closes angular#5099
caitp added a commit to caitp/angular.js that referenced this issue Jan 9, 2014
Before this patch, with modern versions of jQuery being used, the
element data cache was not being copied over into the new element
when replacing an asynchronous directive's compile node with its
template. This caused an issue where the element passed into a
post link function's scope() method would return the incorrect
scope.

The test which is added passes regardless of the change in jQuery
1.10.2, which is currently checked into the tree, but fails without
the change in jQuery 2.0.3.

Closes angular#5099
caitp added a commit to caitp/angular.js that referenced this issue Jan 9, 2014
Before this patch, with modern versions of jQuery being used, the
element data cache was not being copied over into the new element
when replacing an asynchronous directive's compile node with its
template. This caused an issue where the element passed into a
post link function's scope() method would return the incorrect
scope.

The test which is added passes regardless of the change in jQuery
1.10.2, which is currently checked into the tree, but fails without
the change in jQuery 2.0.3.

Closes angular#5099
@caitp
Copy link
Contributor

caitp commented Jan 9, 2014

I think that's about ready ^_^ checkin-needed

@tbosch tbosch modified the milestones: 1.2.12, 1.2.11, 1.2.13 Feb 3, 2014
@btford btford modified the milestones: 1.2.14, 1.2.13 Feb 15, 2014
@IgorMinar IgorMinar modified the milestones: 1.3.0-beta.1, 1.2.14 Mar 1, 2014
@btford btford modified the milestones: 1.3.0-beta.2, 1.3.0-beta.1 Mar 10, 2014
@tbosch tbosch modified the milestones: 1.3.0-beta.3, 1.3.0-beta.2 Mar 14, 2014
@btford btford modified the milestones: 1.3.0-beta.4, 1.3.0-beta.3 Mar 24, 2014
@jeffbcross jeffbcross added this to the 1.3.0-beta.6 milestone Apr 3, 2014
@jeffbcross jeffbcross removed this from the 1.3.0-beta.5 milestone Apr 3, 2014
@IgorMinar IgorMinar modified the milestones: 1.3.0-beta.7, 1.3.0-beta.6 Apr 22, 2014
@caitp caitp modified the milestones: 1.3.0-beta.9, 1.3.0-beta.8 May 9, 2014
@IgorMinar IgorMinar modified the milestones: 1.3.0, 1.3.0-beta.9 May 12, 2014
@mgol
Copy link
Member

mgol commented Aug 4, 2014

Works fine with jQuery 2.1.1 and Angular snapshot:
http://plnkr.co/edit/EKtHEQkw06sY88YY2w81?p=preview

Older Angular versions don't support jQuery 2.x. I'm closing this issue; please comment if I omitted something.

@mgol mgol closed this as completed Aug 4, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.