In Angular 2 I want to put something line ng-content
into ngFor
inside of my component. But the problem is I need to pass some data ito the transcluded element.
I found following solution for AgularJS:
http://plnkr.co/edit/aZKFqPJmPlfTVRffB0Cc?p=preview
.directive("foo", function($compile){
return {
scope: {},
transclude: true,
link: function(scope, element, attrs, ctrls, transclude){
scope.items = [1, 2, 3, 4];
var template = '<h1>I am foo</h1>\
<div ng-repeat="$item in items">\
<placeholder></placeholder>\
</div>';
var templateEl = angular.element(template);
transclude(scope, function(clonedContent){
templateEl.find("placeholder").replaceWith(clonedContent);
$compile(templateEl)(scope, function(clonedTemplate){
element.append(clonedTemplate);
});
});
}
};
});
How can I make the same thing in Angular 2?