Is it possible to use
(and its select option) inside a
or does it only works within a component ?
You can use ng-content inside ng-template.
This is something I put together a while back demonstrating putting the ng-content somewhere on dom based on property. look at the html of tabs.component to see this in use.
https://stackblitz.com/edit/mobile-ng-content
As far as i know it is not possible using ng-content
, but you can provide parameters to the template. So it's possible to pass another NgTemplate
, which can again be used with an NgTemplateOutlet
inside the original template. Here's a working example:
<ng-container *ngTemplateOutlet="tpl, context: {$implicit: paramTemplate}">
</ng-container>
<ng-template #paramTemplate>
<span>Hello</span>
</ng-template>
<ng-template #tpl let-param>
<ng-container *ngTemplateOutlet="param"></ng-container> World !
</ng-template>
Actually it is even possible to pass multiple templates to the original template:
<ng-container *ngTemplateOutlet="tpl, context: {'param1': paramTemplate1, 'param2': paramTemplate2}">
</ng-container>
<ng-template #paramTemplate1>
<span>Hello</span>
</ng-template>
<ng-template #paramTemplate2>
<span>World</span>
</ng-template>
<ng-template #tpl let-param1="param1" let-param2="param2">
<ng-container *ngTemplateOutlet="param1"></ng-container>
<ng-container *ngTemplateOutlet="param2"></ng-container>
</ng-template>