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

Commit b9ddef2

Browse files
petebacondarwincaitp
authored andcommitted
fix($compile): don't pass transcludes to non-transclude templateUrl directives
1 parent eafba9e commit b9ddef2

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
13191319
}
13201320

13211321
nodeLinkFn = compileTemplateUrl(directives.splice(i, directives.length - i), $compileNode,
1322-
templateAttrs, jqCollection, childTranscludeFn, preLinkFns, postLinkFns, {
1322+
templateAttrs, jqCollection, hasTranscludeDirective && childTranscludeFn, preLinkFns, postLinkFns, {
13231323
controllerDirectives: controllerDirectives,
13241324
newIsolateScopeDirective: newIsolateScopeDirective,
13251325
templateDirective: templateDirective,

test/ng/compileSpec.js

+36
Original file line numberDiff line numberDiff line change
@@ -3797,6 +3797,42 @@ describe('$compile', function() {
37973797
});
37983798

37993799

3800+
it('should not pass transclusion into a templateUrl directive', function() {
3801+
3802+
module(function($compileProvider) {
3803+
3804+
$compileProvider.directive('transFoo', valueFn({
3805+
template: '<div>' +
3806+
'<div no-trans-bar></div>' +
3807+
'<div ng-transclude>this one should get replaced with content</div>' +
3808+
'<div class="foo" ng-transclude></div>' +
3809+
'</div>',
3810+
transclude: true
3811+
3812+
}));
3813+
3814+
$compileProvider.directive('noTransBar', valueFn({
3815+
templateUrl: 'noTransBar.html',
3816+
transclude: false
3817+
3818+
}));
3819+
});
3820+
3821+
inject(function($compile, $rootScope, $templateCache) {
3822+
$templateCache.put('noTransBar.html',
3823+
'<div>' +
3824+
// This ng-transclude is invalid. It should throw an error.
3825+
'<div class="bar" ng-transclude></div>' +
3826+
'</div>');
3827+
3828+
expect(function() {
3829+
element = $compile('<div trans-foo>content</div>')($rootScope);
3830+
$rootScope.$apply();
3831+
}).toThrowMinErr('ngTransclude', 'orphan',
3832+
'Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found. Element: <div class="bar" ng-transclude="">');
3833+
});
3834+
});
3835+
38003836
it('should make the result of a transclusion available to the parent directive in post-linking phase' +
38013837
'(template)', function() {
38023838
module(function() {

0 commit comments

Comments
 (0)