Having a property on the object should help you
<div *ngFor="let item of items" style="border: solid 1px; padding: 20px;margin: 20px;">
<span style="color:red"> {{item.name}} </span>
<ng-container *ngComponentOutlet="item.component"><ng-container>
<br>
</div>
Array object should be as
items:Array<any> = [
{
name: 'slider'
component: sliderComponent
},
{
name: 'user'
component: usersComponent
},
{
name: 'slider'
component: sliderComponent
},
{
name: 'alert danger'
component: AlertDangerComponent
}
]
Ensure that all the components are loaded by using them in the AppModule
entryComponents: [AlertDangerComponent, AlertSuccessComponent, usersComponent, sliderComponent ]
LIVE DEMO
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…