fix($compile): don't pass transcludes to non-transclude templateUrl directives

This commit is contained in:
Peter Bacon Darwin
2014-05-26 22:21:20 +01:00
committed by Vojta Jina
parent e3003d5342
commit 2ee29c5da8
2 changed files with 37 additions and 1 deletions

View File

@@ -1336,7 +1336,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,

View File

@@ -4021,6 +4021,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() {