I wrote a directive that dynamically creates a popover for an element:
app.directive('popover', function($compile, $timeout){
return {
link: function(scope, element, attrs) {
$timeout(function() {
var tpl = $(element).find('.popover-template')
var template = {
title: tpl.find('.template-title').contents(),
content: tpl.find('.template-content').contents()
};
var content = $compile(template.content)(scope);
var title = $compile(template.title)(scope);
$(element).popover({
html: true,
placement: "right",
content: content,
title: title
});
scope.$digest()
});
}
};
});
In the application, it looks like this:
<span popover>Click me</span>
<div ng-hide="true" class="popover-template">
<div class="template-title">
<strong>{{ x.name }} and {{ y.name }}</strong>
</div>
<div class="template-content">
<div>
<pre>f in [1,2,3]</pre>
<div ng-repeat="f in [1,2,3]">
item {{ f }}, index {{ $index }}
</div>
</div>
</div>
</div>
A popover is created and displayed. The name also works correctly. However, ng-repeat is applied several times in any iteration:

As you can see, the iteration, which should only include 3 elements, includes 3 * 3 elements. The directive creates popovers for exactly 3 elements, so I assume that where my mistake is. How can I make sure that inside each popover, it ng-repeatis called only once?
doque