问题
In my app.component.ts I have an array with the component tags.
compData = ['app-component-one', 'app-component-two', 'app-component-three'];
Then in my app.component.html I have this:
<div *ngFor="let comps of compData">
// I tried this: {{comps}} but that will not render the components
</div>
How can I do this so I can render each component?
回答1:
You cannot render components from array, instead you need to look at dynamic component generator
https://angular.io/guide/dynamic-component-loader
来源:https://stackoverflow.com/questions/48525649/render-components-from-array-loop