Transclusion doesn't handle changes to the content and doesn't allow CSS selectors #15330
Description
Do you want to request a feature or report a bug?
Mostly a feature, kind of a bug
What is the current behavior?
Content is transcluded in the way I expect, but an error is thrown and angular doesn't properly bind to the transcluded content.
Minimal reproduction of the problem with instructions
Main directive:
directive('myDirective', function () {
return {
restrict: 'EA',
scope: {},
bindToController: {
...
},
controllerAs: 'ctrl',
templateUrl: ...,
link: linkfn,
controller: ctrlfn,
transclude: {
'slotA': 'sectionA',
'slotB': 'sectionB'
}
}
function linkfn(scope, elem, attrs, ctrl) {
...
}
function ctrlfn($scope, $element) {
...
}
})
Template for main directive:
...
<section class="..." my-directive-transclude="slotA"></section>
<section class="..." my-directive-transclude="slotB"></section>
...
Subsidiary directive:
directive('myDirectiveTransclude', function () {
return {
restrict: 'A',
require: '^myDirective',
scope: false,
link: function (scope, elem, attrs, ctrl, transclude) {
var slot = attrs.myDirectiveTransclude
transclude(function (clone) {
elem.empty()
elem.append(clone.children())
}, elem, slot)
}
}
})
The page:
...
<my-directive>
<section-a>
content
</section-a>
<section-b>
content
</section-b>
</my-directive>
...
causes
TypeError: Cannot read property 'childNodes' of undefined
at nodeLinkFn (http://.../angular.js:9330:58)
at compositeLinkFn (http://.../angular.js:8620:13)
at compositeLinkFn (http://.../angular.js:8623:13)
at compositeLinkFn (http://.../angular.js:8623:13)
at publicLinkFn (http://.../angular.js:8500:30)
at lazyCompilation (http://.../angular.js:8844:25)
at boundTranscludeFn (http://.../angular.js:8637:16)
at controllersBoundTransclude (http://.../angular.js:9377:22)
at Object.link (http://.../my-script.js:##:##)
at http://.../angular.js:1247:18
What is the expected behavior?
Content is transcluded in the way I expect and everything works.
What is the motivation / use case for changing the behavior?
I want to be able to transclude section-a and section-b into my-directive, but I want real tags and I don't want things nested obnoxiously.
Please tell us about your environment:
Visual Studio 2013, Nuget, Windows 10, IIS 7.5 (or whatever comes with win 10).
- Angular version: 1.5.8
- Browser: IE 11, Chrome 52 (I don't support anything else).
- Language: ES5