【问题标题】:Render Components from Array loop从数组循环渲染组件
【发布时间】:2018-07-09 14:06:58
【问题描述】:

在我的 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>

如何才能渲染每个组件?

【问题讨论】:

  • 你试过&lt;{{comps}}&gt;&lt;/{{comps}}&gt; 吗?
  • @JiiB,你真的认为它会起作用吗?
  • 你不能那样做
  • @Qwertiy 不,我完全不确定。但通常你写你的组件标签就像一个正常的打开和关闭 html 标签

标签: angular typescript angular5


【解决方案1】:

您不能从数组中渲染组件,而是需要查看动态组件生成器

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

【讨论】:

    猜你喜欢
    • 2018-08-08
    • 2020-12-16
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多