My goal is to have a directive, which I give contents to, and it repeats them X times. Just like ng-repeat, only I want to wrap it in other features such as limit toggle and extra elements outside the transcluded content.
For some reason, the transclusion has no access to the directive isolate scope, no matter what I try.
I've used the transclude function inside link, in several variations, to no avail. Here's a demo:
And here's the gist of the code:
app.directive('repeatContents', function() {
return {
scope: {
items: '=repeatContents',
limit: '=repeatLimit'
},
transclude: true,
template: '<div ng-repeat="item in items">' +
'<em>Outside transclude: {{item}}</em><br />' +
'<ng-transclude></ng-transclude>' +
'</div>',
link: function(scope, el, attrs, ctrl, transclude) {
transclude(scope, function(clone, scope) {
el.append(clone);
});
}
}
});
If you look at the plunkr, you will see that outside the transclusion {{item}} is available, but not inside. Regardless of the link function's contents which were supposed to take care of it. Any idea what I can do?