I would like to decide which sub-component to use programmatically. It is basically the same question asked here Load component programmatically in angular 1.6, but using Angular 6.
So, I would like to have something like this:
parent.component.ts
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-parent',
templateUrl: './parent.component.html',
styleUrls: ['./parent.component.css']
})
export class ParentComponent implements OnInit {
@Input() loadedComponentName = "my-component";
constructor() { }
ngOnInit() {
}
}
parent.component.html
<{{loadedComponentName}}></{{loadedComponentName}}>