I'm trying to build a multi-select component which can take a template for each select option element. It's mostly working, the templates are grabbed from the ng-content in the option component and displays in the "select popover" fine.
I'm having issues when trying to display the selected option in the select component. It seems that the template can only be shown in one place at a time, so when the selected option is displayed in the select, it is removed from the popover.
Is there any way I could clone the TemplateRef component? I don't actually mind if the context doesn't update for the template as I'm not currently using anything from it, just the template.
Including some code snips below for clarity, I think it's okay though.
Usage in somepage.component.html:
<my-select [(value)]="vals">
<my-option *ngFor="let x of [1,2,3]" [value]="x">Option {{x}}</my-option>
</my-select>`
my-select.component.html
...
<ng-container [ngTemplateOutlet]="getSelectedOptionTemplate()"></ng-container>
...
my-select.component.ts
getSelectedOptionTemplate(){
// Some way to clone here could solve the issue?
return this.getSelectedOption().template;
}
my-select-overlay.component.html
...
<ng-container *ngFor="let opt of options;">
<ng-container [ngTemplateOutlet]="getTemplate(opt)"></ng-container>
</ng-container>
...
my-option.component.html
<ng-template>
<ng-content></ng-content>
</ng-template>
my-option.component.ts
...
@ViewChild(TemplateRef)
template: TemplateRef<any>;
...

