Render Components from Array loop

一世执手 提交于 2019-12-22 13:48:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!