After some tinkering I found a solution. I created two new directives to replace the default ng-transcude
, and a helper service that stores the state shared between the directives. Together they allow the deep transclusion that I was looking for.
The first stores $transclude into the service; it must be used within every directive that can be given transcludible content in a template:
controller: ['$transclude', 'TransclusionHelper', function($transclude,TransclusionHelper) {
TransclusionHelper.setTransclusionFn($transclude);
}],
The second performs the transclusion of the content to its final location; it need not be used in directives that only pass through their transcluded content to a child:
link: ['$element','TransclusionHelper', function($element,TransclusionHelper) {
TransclusionHelper.transclude(function(clone) {
$element.empty();
$element.append(clone);
});
}],
Some finesse is required in the service to manage state; if several calls to setTransclusionFn
are made before a call to transclude
, only the first should be stored and used when transclude is called.