I'm trying to build a "chart widget" directive with a clone button that will clone the chart and append it right after the original.
The directive looks like this:
app.directive("chartWidget", function ($compile) {
return {
restrict: "A",
transclude: true,
templateUrl: 'chart-widget-template',
link: function ($scope, element, attrs) {
$scope.clone = function () {
var clone = $compile("chart-widget-template")($scope);
element.after(clone);
};
}
};
});
With the template as follows:
<script type="text/ng-template" id="chart-widget-template">
<section class="widget chart-widget">
<i ng-click="clone()" class="widget-clone-handle"></i>
<div class="body no-margin">
<div ng-transclude></div>
</div>
</section>
</script>
And usage as follows:
<div data-chart-widget>
<div data-some-specific-chart-directive></div>
</div>
At first I tested the cloning to work without transclusion succesfully. However, once I add the transclusion in the mix, cloning it produces this error:
Error: [ngTransclude:orphan] Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found. Element:
The angular docs for $compile state that the transcludeFn parameter to $compile is depracated (not that I know how it works anyways), so how would I accomplish this?
To clarify, I want the original transclusion aka:
<div data-some-specific-chart-directive></div>
to be included in each clone.