I encountered a problem with ng-template.
In our table component, we pass parameters using ngTemplateOutletContext as shown below. Depending on the data type, we use different renderers for the cells. Pay attention to the cellvalue parameter, it is crucial for my needs.
<ng-container *ngIf="useCellRenderer(column, row)">
<ng-template [ngTemplateOutlet]="column.renderer.templateref" [ngTemplateOutletContext]="{ cellvalue: row[column.attr], rowvalue:row }">
</ng-template>
</ng-container>
The template within the rendering component appears like this:
<ng-template #templateRef let-cellvalue="cellvalue" let-rowvalue="rowvalue">
{{ getTraslateValue(cellvalue)}}
</ng-template>
Although the template can access the cellvalue parameter and function correctly, I am struggling to access the same parameter from the TS component.
I have attempted the following snippet so far:
@ViewChild('templateRef', { read: TemplateRef })
public templateref: TemplateRef<any>;
ngAfterViewInit() {
console.log('ngAfterViewInit', this.templateref.elementRef);
}
However, the cellvalue does not appear in the console.log.
Thank you in advance!