import { AfterViewInit, Component, ContentChild, TemplateRef, ViewContainerRef } from '@angular/core';
@Component({
selector: 'my-projection',
template: `<ng-template #contentTemplate><ng-content></ng-content></ng-template>`,
})
export class MyProjectionComponent implements AfterViewInit {
@ContentChild('contentTemplate', { static: true }) contentTemplate!: TemplateRef<any>;
constructor(private viewContainerRef: ViewContainerRef) {}
ngAfterViewInit() {
// Move projected content to parent container
this.viewContainerRef.createEmbeddedView(this.contentTemplate);
}
}