I came up with this directive using the transclude function:
app.directive('mainDirective', function($compile) { var template = ['<div>', ' <div class="left">', ' <div data-ng-multi-transclude="sub"></div>', ' <div class="bottomOptions">', ' <span class="csStIcon collapse"></span>', ' <div data-ng-multi-transclude="subButtons"></div>', ' </div>', ' </div>', ' <div class="right">', ' <div data-ng-multi-transclude="main"></div>', ' </div>', '</div>'].join('\n'); return { restrict: 'C', transclude: true, template: template, link: function(scope, element, attr, model, transclude) { var places = element.find('[data-ng-multi-transclude]'); console.log(element); places.each(function() { var self = $(this); var class_ = self.data('ng-multi-transclude'); transclude(scope.$new(), function(clone, scope) { var item = clone.closest('.' + class_); $compile(item)(scope).appendTo(self); }); }); } }; });
I used compilation so you can use angular inside your translated code.
If you use this:
self.replaceWith($compile(item)(scope));
you won't get those original div wrappers with data-ng-multi-transclude .
You also need to enable jQuery (always before Angular, because otherwise you will get jQLite).
source share