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

Commit 83857c3

Browse files
committed
feat($compile): expose publicLinkFn options
Use `options` object hash style parameter for publicLinkFn. Expose `options` parameter as part of the public API. Closes #9413.
1 parent fecfe84 commit 83857c3

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

src/ng/compile.js

+34-4
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,17 @@
620620
*
621621
*
622622
* @param {string|DOMElement} element Element or HTML string to compile into a template function.
623-
* @param {function(angular.Scope, cloneAttachFn=)} transclude function available to directives.
623+
* @param {function(angular.Scope, cloneAttachFn=)} transclude function available to directives - DEPRECATED.
624+
*
625+
* <div class="alert alert-error">
626+
* **Note:** Passing a `transclude` function to the $compile function is deprecated, as it
627+
* e.g. will not use the right outer scope. Please pass the transclude function as a
628+
* `parentBoundTranscludeFn` to the link function instead.
629+
* </div>
630+
*
624631
* @param {number} maxPriority only apply directives lower than given priority (Only effects the
625632
* root element(s), not their children)
626-
* @returns {function(scope, cloneAttachFn=)} a link function which is used to bind template
633+
* @returns {function(scope, cloneAttachFn=, options=)} a link function which is used to bind template
627634
* (a DOM element/tree) to a scope. Where:
628635
*
629636
* * `scope` - A {@link ng.$rootScope.Scope Scope} to bind to.
@@ -635,6 +642,19 @@
635642
* * `clonedElement` - is a clone of the original `element` passed into the compiler.
636643
* * `scope` - is the current scope with which the linking function is working with.
637644
*
645+
* * `options` - An optional object hash with linking options. If `options` is provided, then the following
646+
* keys may be used to control linking behavior:
647+
*
648+
* * `parentBoundTranscludeFn` - the transclude function made available to
649+
* directives; if given, it will be passed through to the link functions of
650+
* directives found in `element` during compilation.
651+
* * `transcludeControllers` - an object hash with keys that map controller names
652+
* to controller instances; if given, it will make the controllers
653+
* available to directives.
654+
* * `futureParentElement` - defines the parent to which the `cloneAttachFn` will add
655+
* the cloned elements; only needed for transcludes that are allowed to contain non html
656+
* elements (e.g. SVG elements). See also the directive.controller property.
657+
*
638658
* Calling the linking function returns the element of the template. It is either the original
639659
* element passed in, or the clone of the element if the `cloneAttachFn` is provided.
640660
*
@@ -1153,8 +1173,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
11531173
maxPriority, ignoreDirective, previousCompileContext);
11541174
compile.$$addScopeClass($compileNodes);
11551175
var namespace = null;
1156-
return function publicLinkFn(scope, cloneConnectFn, parentBoundTranscludeFn, transcludeControllers, futureParentElement){
1176+
return function publicLinkFn(scope, cloneConnectFn, options){
11571177
assertArg(scope, 'scope');
1178+
1179+
options = options || {};
1180+
var parentBoundTranscludeFn = options.parentBoundTranscludeFn,
1181+
transcludeControllers = options.transcludeControllers,
1182+
futureParentElement = options.futureParentElement;
1183+
11581184
if (!namespace) {
11591185
namespace = detectNamespaceForChildElements(futureParentElement);
11601186
}
@@ -1324,7 +1350,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
13241350
transcludedScope.$$transcluded = true;
13251351
}
13261352

1327-
return transcludeFn(transcludedScope, cloneFn, previousBoundTranscludeFn, controllers, futureParentElement);
1353+
return transcludeFn(transcludedScope, cloneFn, {
1354+
parentBoundTranscludeFn: previousBoundTranscludeFn,
1355+
transcludeControllers: controllers,
1356+
futureParentElement: futureParentElement
1357+
});
13281358
};
13291359

13301360
return boundTranscludeFn;

src/ng/directive/ngInclude.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ var ngIncludeFillContentDirective = ['$compile',
284284
$compile(jqLiteBuildFragment(ctrl.template, document).childNodes)(scope,
285285
function namespaceAdaptedClone(clone) {
286286
$element.append(clone);
287-
}, undefined, undefined, $element);
287+
}, {futureParentElement: $element});
288288
return;
289289
}
290290

test/ng/compileSpec.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5153,7 +5153,9 @@ describe('$compile', function() {
51535153
tElement.empty();
51545154
return function(scope, element, attrs, ctrls, transcludeFn) {
51555155
element.append(content);
5156-
$compile(content)(scope, undefined, transcludeFn);
5156+
$compile(content)(scope, undefined, {
5157+
parentBoundTranscludeFn: transcludeFn
5158+
});
51575159
};
51585160
}
51595161
};

0 commit comments

Comments
 (0)