But this does not work if the template is in another component. How do you pass the context object in such a scenario?
I added
@Input() itemTemplate: TemplateRef<any>;
in the component where I will use it, and in the template of this component I write something like this:
<ng-container *ngTemplateOutlet="itemTemplate; context: item"></ng-container>
Template code on the component side:
<ng-template #dataRendererTpl let-data="data">
<div class="data">Hello, {{data.name}}</div>
Just pass the link to dataRendererTpl as the @Input () property to the component where you need it
source
share