-
Notifications
You must be signed in to change notification settings - Fork 27.5k
fix($compile): fix scoping for transclusion #12975
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5629,6 +5629,63 @@ describe('$compile', function() { | |
}); | ||
|
||
|
||
//see issue https://github.com/angular/angular.js/issues/12936 | ||
it('should use the proper scope when being the root element of a replaced directive', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for completeness, would it be possible to have the same test with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's necessary, this bug didn't appear for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree we probably don't need a test for |
||
module(function() { | ||
directive('isolate', valueFn({ | ||
scope: {}, | ||
replace: true, | ||
template: '<div trans>{{x}}</div>', | ||
link: function(scope, element, attr, ctrl) { | ||
scope.x = 'iso'; | ||
} | ||
})); | ||
directive('trans', valueFn({ | ||
transclude: 'content', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied it from the other tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lgalfaso : Originally the possible values for |
||
link: function(scope, element, attr, ctrl, $transclude) { | ||
$transclude(function(clone) { | ||
element.append(clone); | ||
}); | ||
} | ||
})); | ||
}); | ||
inject(function($rootScope, $compile) { | ||
element = $compile('<isolate></isolate>')($rootScope); | ||
$rootScope.x = 'root'; | ||
$rootScope.$apply(); | ||
expect(element.text()).toEqual('iso'); | ||
}); | ||
}); | ||
|
||
|
||
//see issue https://github.com/angular/angular.js/issues/12936 | ||
it('should use the proper scope when being the root element of a replaced directive with child scope', function() { | ||
module(function() { | ||
directive('child', valueFn({ | ||
scope: true, | ||
replace: true, | ||
template: '<div trans>{{x}}</div>', | ||
link: function(scope, element, attr, ctrl) { | ||
scope.x = 'child'; | ||
} | ||
})); | ||
directive('trans', valueFn({ | ||
transclude: 'content', | ||
link: function(scope, element, attr, ctrl, $transclude) { | ||
$transclude(function(clone) { | ||
element.append(clone); | ||
}); | ||
} | ||
})); | ||
}); | ||
inject(function($rootScope, $compile) { | ||
element = $compile('<child></child>')($rootScope); | ||
$rootScope.x = 'root'; | ||
$rootScope.$apply(); | ||
expect(element.text()).toEqual('child'); | ||
}); | ||
}); | ||
|
||
|
||
it('should not leak if two "element" transclusions are on the same element (with debug info)', function() { | ||
if (jQuery) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be
if (directive[j].transclude === 'element') {
?Mmm... thinking about this again, it looks like the
transclude === 'element'
option is not handled by this PR. This is still ok, as it looks like it handle the case oftransclude === true
properly