I am trying to make a dynamic ngTempateOutlet
.
I tried as follows:
<ng-container *ngFor="let action of actions">
<ng-container *ngTemplateOutlet="action"; context="{item}"></ng-container>
</ng-container>
<ng-template #DELETE let-item="item">delete</ng-template>
<ng-template #MODIFY let-item="item">modify</ng-template>
Where actions
is ["DELETE", "MODIFY"]
.
It seems that action
inside the *ngFor
doesn't result in DELETE
and MODIFY
, because if I manually insert the values the templates are displayed, otherwise they aren't.
I would avoid doing manual checking in order to keep it dynamic (es:)
<ng-container *ngFor="let action of actions">
<ng-container *ngTemplateOutlet="action === 'delete' ? 'DELETE' : 'MODIFY'"; context="{item}"></ng-container>
</ng-container>