Here's the issue. I need to pass a directive2 into directive1. Directive1 has a dynamic templateUrl. A template has a section that would host transcluded code (another directive). This does not work unless I surround element.find (below) with a $timeout. Once the page is rendered, the directive will be embedded into the template. But I can't get it to work without the timeout.
<directive1>
<directive2></directive>
</directive1>
Directive1
app.directive("directive1", function() {
return {
replace: true,
transclude: true,
template: '<ng-include src="getTemplateUrl()" />',
scope: {
id: "="
},
link: function (scope, element, attrs, controller, transclude) {
scope.getTemplateUrl = function () {
return "template" + scope.id + ".html";
};
element.find(".placeholderForDirective2").append(transclude());
}
}
})
Template1:
<div>
<div class="placeholderForDirective2"></div>
<div>blah blah blah</div>
</div>