In my project, I have constructed a wrapper component named wrapperComponent:
export class Wrappercomponent {
@ContentChild(TemplateRef) detailRef;
toggleComponents: boolean = false;
constructor() {}
toggle() {
this.toggleComponents = !this.toggleComponents;
}
}
Additionally, I have this specific template html:
<div *ngIf="toggleComponents; else plugintemplate">
<ng-container *ngTemplateOutlet="detailRef"></ng-container>
</div>
<ng-template #plugintemplate></ng-template>
<button (click)="toggle()">Toggle</button>
My goal is to be able to toggle between two components residing inside my wrapper component (my-component-1 and my-component-2):
<wrapper-component>
<ng-template #detailRef>
<my-component-1></my-component-1>
</ng-template>
<my-component-2></my-component-2>
<wrapper-component>
However, based on my current logic, only the component inserted into templateRef detailRef is visible, while the other one (my-component-2) remains hidden. How can I successfully insert both components into separate containers?