I\'m trying to bind transcluded content to a variable inside of a component loop but I\'m unable to do so.
I\'ve looked at the PrimeNG\'s dropdown
compo
Update Angular 6
ngOutletContext
was renamed to ngTemplateOutletContext
template
should be ng-template
See also https://github.com/angular/angular/blob/master/CHANGELOG.md#500-beta5-2017-08-29
Original
You can get the template reference and add it using for example ngTemplateOutlet
or ngForTemplate
to get the template content added to the DOM. With ngTemplateOutlet
you can provide your own context that you then can access with template variables as you tried.
class CompComponent {
context = {option: 'some option'};
constructor(private templateRef:TemplateRef){}
}
<ng-template [ngTemplateOutlet]="templateRef" [ngOutletContext]="{$implicit: context}"></ng-template>
I think in newer versions this needs to be
<ng-template [ngTemplateOutlet]="templateRef" [ngTemplateOutletContext]="{$implicit: context}"></ng-template>
(but haven't yet verified)
See also