从Array循环渲染组件

问题描述 投票:2回答:1

在我的app.component.ts中,我有一个带有组件标签的数组。

compData = ['app-component-one', 'app-component-two', 'app-component-three'];

然后在我的app.component.html中我有这个:

<div *ngFor="let comps of compData">

    // I tried this: {{comps}} but that will not render the components

</div>

我该怎么做才能渲染每个组件?

angular typescript angular5
1个回答
4
投票

您无法从数组渲染组件,而是需要查看动态组件生成器

https://angular.io/guide/dynamic-component-loader

© www.soinside.com 2019 - 2024. All rights reserved.