Is there a way to insert dynamically a component as a child (not a sibling) of a DOM tag in Angular 2?
There are plenty of examples around there to
Easier approache is now available with Portal available in @angular/cdk.
npm i @angular/cdk
app.module.ts:
import { PortalModule } from '@angular/cdk/portal';
@NgModule({
imports: [PortalModule],
entryComponents: [MyDynamicComponent]
})
SomeComponent:
@Component({
selector: 'some-component',
template: ` `
})
export class SomeComponent {
...
this.myPortal = new ComponentPortal(MyDynamicComponent);
}