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

Commit

Permalink
fix($compile): don't pass transcludes to non-transclude templateUrl d…
Browse files Browse the repository at this point in the history
…irectives
  • Loading branch information
petebacondarwin authored and caitp committed Jun 13, 2014
1 parent eafba9e commit b9ddef2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}

nodeLinkFn = compileTemplateUrl(directives.splice(i, directives.length - i), $compileNode,
templateAttrs, jqCollection, childTranscludeFn, preLinkFns, postLinkFns, {
templateAttrs, jqCollection, hasTranscludeDirective && childTranscludeFn, preLinkFns, postLinkFns, {
controllerDirectives: controllerDirectives,
newIsolateScopeDirective: newIsolateScopeDirective,
templateDirective: templateDirective,
Expand Down
36 changes: 36 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3797,6 +3797,42 @@ describe('$compile', function() {
});


it('should not pass transclusion into a templateUrl directive', 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({
templateUrl: 'noTransBar.html',
transclude: false

}));
});

inject(function($compile, $rootScope, $templateCache) {
$templateCache.put('noTransBar.html',
'<div>' +
// This ng-transclude is invalid. It should throw an error.
'<div class="bar" ng-transclude></div>' +
'</div>');

expect(function() {
element = $compile('<div trans-foo>content</div>')($rootScope);
$rootScope.$apply();
}).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() {
Expand Down

0 comments on commit b9ddef2

Please sign in to comment.