mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-18 07:50:52 +08:00
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:
committed by
Caitlin Potter
parent
6f1d9f8ca6
commit
eafba9e2e5
@@ -907,7 +907,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
||||
!childNodes.length)
|
||||
? null
|
||||
: compileNodes(childNodes,
|
||||
nodeLinkFn ? nodeLinkFn.transclude : transcludeFn);
|
||||
nodeLinkFn ? (
|
||||
(nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement)
|
||||
&& nodeLinkFn.transclude) : transcludeFn);
|
||||
|
||||
linkFns.push(nodeLinkFn, childLinkFn);
|
||||
linkFnFound = linkFnFound || nodeLinkFn || childLinkFn;
|
||||
@@ -942,14 +944,17 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
||||
childScope = scope;
|
||||
}
|
||||
|
||||
// We need to create a new boundTranscludeFn if
|
||||
// - a directive on this element wants to transclude
|
||||
// or
|
||||
// - there is no parentBoundTranscludeFn already and a transcludeFn was passed in
|
||||
if ( nodeLinkFn.transcludeOnThisElement || (!parentBoundTranscludeFn && transcludeFn) ) {
|
||||
childBoundTranscludeFn = createBoundTranscludeFn(scope, nodeLinkFn.transclude || transcludeFn, parentBoundTranscludeFn);
|
||||
} else {
|
||||
if ( nodeLinkFn.transcludeOnThisElement ) {
|
||||
childBoundTranscludeFn = createBoundTranscludeFn(scope, nodeLinkFn.transclude, parentBoundTranscludeFn);
|
||||
|
||||
} else if (!nodeLinkFn.templateOnThisElement && parentBoundTranscludeFn) {
|
||||
childBoundTranscludeFn = parentBoundTranscludeFn;
|
||||
|
||||
} else if (!parentBoundTranscludeFn && transcludeFn) {
|
||||
childBoundTranscludeFn = createBoundTranscludeFn(scope, transcludeFn);
|
||||
|
||||
} else {
|
||||
childBoundTranscludeFn = null;
|
||||
}
|
||||
|
||||
nodeLinkFn(childLinkFn, childScope, node, $rootElement, childBoundTranscludeFn);
|
||||
@@ -1164,6 +1169,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
||||
templateDirective = previousCompileContext.templateDirective,
|
||||
nonTlbTranscludeDirective = previousCompileContext.nonTlbTranscludeDirective,
|
||||
hasTranscludeDirective = false,
|
||||
hasTemplate = false,
|
||||
hasElementTranscludeDirective = previousCompileContext.hasElementTranscludeDirective,
|
||||
$compileNode = templateAttrs.$$element = jqLite(compileNode),
|
||||
directive,
|
||||
@@ -1254,6 +1260,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
||||
}
|
||||
|
||||
if (directive.template) {
|
||||
hasTemplate = true;
|
||||
assertNoDuplicate('template', templateDirective, directive, $compileNode);
|
||||
templateDirective = directive;
|
||||
|
||||
@@ -1303,6 +1310,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
||||
}
|
||||
|
||||
if (directive.templateUrl) {
|
||||
hasTemplate = true;
|
||||
assertNoDuplicate('template', templateDirective, directive, $compileNode);
|
||||
templateDirective = directive;
|
||||
|
||||
@@ -1340,6 +1348,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
||||
|
||||
nodeLinkFn.scope = newScopeDirective && newScopeDirective.scope === true;
|
||||
nodeLinkFn.transcludeOnThisElement = hasTranscludeDirective;
|
||||
nodeLinkFn.templateOnThisElement = hasTemplate;
|
||||
nodeLinkFn.transclude = childTranscludeFn;
|
||||
|
||||
previousCompileContext.hasElementTranscludeDirective = hasElementTranscludeDirective;
|
||||
|
||||
Reference in New Issue
Block a user