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 was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Removing part of transclude destroys transclusion scope. #5703
I have a directive which has an isolated scope, template and transclusion. I use the transclude function in the directive's link (as expected the transclusion is bound to the parent scope, not the isolated one) to clone the template and add it to the dom. The transclusion contains several elements.
As part of the directive I sometimes remove a single element that was part of the transcluded content from the dom. This triggers $destroy on the element which destroys the transclusion scope (although there are still other elements that use it).
The $destroy binding is done in createBoundTranscludeFn().
Unless I'm missing something this seems like a bug to me.
it's not really clear what the use case is, but it seems unexpected that you get that "disconnect" effect just for removing one of the transcluded children.
) --- When the element gets destroy'd, so does its scope because it has no relatives (I assume, it's not totally obvious, :z how that cleanup works).
But yeah, the $rootScope continues to exist, but the bindings weren't actually referencing the $rootScope at all, but a child scope of it. This is made a bit more evident with this repro http://plnkr.co/edit/anGizYY7vXAoPvudc8bD?p=preview.
Anyways, I guess this is actually the expected behaviour, although it still totally weirds me out that we create a new scope by default there.
It's sort of related to #5489 (because ngTransclude also calls the controllersBoundTransclude with just the attach function
It only creates a new scope because you aren't explicitly passing a scope to the transclude function. So in 1.2.1 you have a workaround for this, but not if you don't call the transclude function with a scope as the first argument.
Activity
caitp commentedon Jan 9, 2014
It doesn't seem to break when you remove a part of your template, only when you remove one of the transcluded elements. Hm
yarontt commentedon Jan 9, 2014
Ah... right.
Sorry, I guess I got mixed up when writing the issue. I'll edit to reflect the correct issue.
tbosch commentedon Jan 10, 2014
Would be really great to have more info about your use case in a plunker/fiddle.
caitp commentedon Jan 10, 2014
it's not really clear what the use case is, but it seems unexpected that you get that "disconnect" effect just for removing one of the transcluded children.
caitp commentedon Jan 10, 2014
You know what this is, it's that we're creating a new scope (
angular.js/src/ng/compile.js
Line 953 in c894470
angular.js/src/ng/compile.js
Line 1542 in c894470
But yeah, the $rootScope continues to exist, but the bindings weren't actually referencing the $rootScope at all, but a child scope of it. This is made a bit more evident with this repro http://plnkr.co/edit/anGizYY7vXAoPvudc8bD?p=preview.
Anyways, I guess this is actually the expected behaviour, although it still totally weirds me out that we create a new scope by default there.
It's sort of related to #5489 (because ngTransclude also calls the controllersBoundTransclude with just the attach function
angular.js/src/ng/directive/ngTransclude.js
Line 71 in c894470
Honestly, we should just throw a minErr instead (and of course, pass a proper scope to ng-transclude's controllersBoundTransclude)
I think I can sleep now ㄱ______ㄱ
yarontt commentedon Jan 10, 2014
Ah... there's a jsfiddle up there in the issue description.
Just click the "click me" and see that the binding is destroyed.
I think there's no need to create a new scope. Or at least have some something place that destroys it only if all of its elements are destroyed.
caitp commentedon Jan 10, 2014
It only creates a new scope because you aren't explicitly passing a scope to the transclude function. So in 1.2.1 you have a workaround for this, but not if you don't call the transclude function with a scope as the first argument.
yarontt commentedon Jan 11, 2014
Yes, I've figured that out already and am using this workaround for now.
Still seems like a bug to me (took me a long time to figure out why my code wasn't working as I expected).
Bring back the transclusion. Close #285.
dlongley commentedon Oct 2, 2014
Sounds like this may have been fixed by #9281.
Narretz commentedon Oct 19, 2014
@dlongley Good catch!
See http://jsfiddle.net/rtwgT/6/