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