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

Commit 2ee29c5

Browse files
petebacondarwinvojtajina
authored andcommitted
fix($compile): don't pass transcludes to non-transclude templateUrl directives
1 parent e3003d5 commit 2ee29c5

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
@@ -1336,7 +1336,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
13361336
}
13371337

13381338
nodeLinkFn = compileTemplateUrl(directives.splice(i, directives.length - i), $compileNode,
1339-
templateAttrs, jqCollection, childTranscludeFn, preLinkFns, postLinkFns, {
1339+
templateAttrs, jqCollection, hasTranscludeDirective && childTranscludeFn, preLinkFns, postLinkFns, {
13401340
controllerDirectives: controllerDirectives,
13411341
newIsolateScopeDirective: newIsolateScopeDirective,
13421342
templateDirective: templateDirective,

test/ng/compileSpec.js

+36
Original file line numberDiff line numberDiff line change
@@ -4021,6 +4021,42 @@ describe('$compile', function() {
40214021
});
40224022

40234023

4024+
it('should not pass transclusion into a templateUrl directive', function() {
4025+
4026+
module(function($compileProvider) {
4027+
4028+
$compileProvider.directive('transFoo', valueFn({
4029+
template: '<div>' +
4030+
'<div no-trans-bar></div>' +
4031+
'<div ng-transclude>this one should get replaced with content</div>' +
4032+
'<div class="foo" ng-transclude></div>' +
4033+
'</div>',
4034+
transclude: true
4035+
4036+
}));
4037+
4038+
$compileProvider.directive('noTransBar', valueFn({
4039+
templateUrl: 'noTransBar.html',
4040+
transclude: false
4041+
4042+
}));
4043+
});
4044+
4045+
inject(function($compile, $rootScope, $templateCache) {
4046+
$templateCache.put('noTransBar.html',
4047+
'<div>' +
4048+
// This ng-transclude is invalid. It should throw an error.
4049+
'<div class="bar" ng-transclude></div>' +
4050+
'</div>');
4051+
4052+
expect(function() {
4053+
element = $compile('<div trans-foo>content</div>')($rootScope);
4054+
$rootScope.$apply();
4055+
}).toThrowMinErr('ngTransclude', 'orphan',
4056+
'Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found. Element: <div class="bar" ng-transclude="">');
4057+
});
4058+
});
4059+
40244060
it('should make the result of a transclusion available to the parent directive in post-linking phase' +
40254061
'(template)', function() {
40264062
module(function() {

0 commit comments

Comments
 (0)