If you need to create components dynamically, you can use ViewContainerRef in Angular. Here is an example:
https://stackblitz.com/edit/angular-4asbmc
(Remember to add the components you want to inject dynamically in your app module's entryComponents)
Once you have inserted the components, you can manage which components should appear based on certain conditions.
You can also iterate over an array of components like this:
let componentArray = [HeaderComponent, BannerComponent, FooterComponent];
Then, loop through this array and insert each component using a method like createComponent() mentioned below:
createComponent(component) {
const factory = this.factoryResolver.resolveComponentFactory(component);
const componentRef = factory.create(yourViewContainerRef.parentInjector);
yourViewContainerRef.insert(componentRef.hostView);
}
Alternatively, you could directly include components in your main app component's HTML template based on conditions:
<app-header *ngIf="yourConditions..."></app-header>
<app-banner *ngIf="otherConditions..."></app-banner>
<!-- and so on.... -->