从数组循环渲染组件 [英] Render Components from Array loop
本文介绍了从数组循环渲染组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的app.component.ts中,我有一个带有组件标签的数组.
In my app.component.ts I have an array with the component tags.
compData = ['app-component-one', 'app-component-two', 'app-component-three'];
然后在我的app.component.html中,我有这个:
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?
推荐答案
您不能从数组中渲染组件,而是需要查看动态组件生成器
You cannot render components from array, instead you need to look at dynamic component generator
https://angular.io/guide/dynamic-component-loader
这篇关于从数组循环渲染组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文