-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Removing part of transclude destroys transclusion scope. #5703
Comments
It doesn't seem to break when you remove a part of your template, only when you remove one of the transcluded elements. Hm |
Ah... right. |
Would be really great to have more info about your use case in a plunker/fiddle. |
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. |
You know what this is, it's that we're creating a new scope ( Line 953 in c894470
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
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 ㄱ______ㄱ |
Ah... there's a jsfiddle up there in the issue description. 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. |
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. |
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). |
The workaround to prevent issue #90 is revealed here, after fair amount of googling: angular/angular.js#5703 Since Angular 1.2.1 we can pass $scope as first argument to $transclude, to prevent it from creating a new scope. We now require Angular >= 1.2.1.
Sounds like this may have been fixed by #9281. |
@dlongley Good catch! |
Hi,
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.
http://jsfiddle.net/yarontt/rtwgT/
The text was updated successfully, but these errors were encountered: