fix($compile): don't pass transclude to template of non-transclude directive

If a directive provides a template but is not explicitly requesting transclusion
then the compiler should not pass a transclusion function to the directives
within the template.
This commit is contained in:
Peter Bacon Darwin
2014-05-23 12:13:27 +01:00
committed by Caitlin Potter
parent 6f1d9f8ca6
commit eafba9e2e5
2 changed files with 50 additions and 8 deletions

View File

@@ -3764,6 +3764,39 @@ describe('$compile', function() {
});
it('should not pass transclusion into a template directive when the directive didn\'t request transclusion', function() {
module(function($compileProvider) {
$compileProvider.directive('transFoo', valueFn({
template: '<div>' +
'<div no-trans-bar></div>' +
'<div ng-transclude>this one should get replaced with content</div>' +
'<div class="foo" ng-transclude></div>' +
'</div>',
transclude: true
}));
$compileProvider.directive('noTransBar', valueFn({
template: '<div>' +
// This ng-transclude is invalid. It should throw an error.
'<div class="bar" ng-transclude></div>' +
'</div>',
transclude: false
}));
});
inject(function($compile, $rootScope) {
expect(function() {
$compile('<div trans-foo>content</div>')($rootScope);
}).toThrowMinErr('ngTransclude', 'orphan',
'Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found. Element: <div class="bar" ng-transclude="">');
});
});
it('should make the result of a transclusion available to the parent directive in post-linking phase' +
'(template)', function() {
module(function() {