【发布时间】:2019-08-18 22:54:57
【问题描述】:
我有这个数组:
this.dashboard = [
{name: '<app-incassi-provvigioni></app-incassi-provvigioni>'},
{name: '<app-scheda-punti-vendita></app-scheda-punti-vendita>'}
]
我在 ngOnInit 循环中填充这个数组。 我想知道当我像这样在 html 中读取数组时如何渲染组件:
<gridster [options]="gridsterOptions">
<gridster-item [item]="item" *ngFor="let item of dashboard">
<!-- your content here -->
{{item.name}}
</gridster-item>
</gridster>
当然,现在它返回包含在对象中的字符串,但我正在尝试找到一种解决方案来呈现组件。 有可能吗?
更多详情: 我正在开发一个仪表板类型的应用程序,我在其中从数据库中检索用户仪表板列表,并且我试图在主应用程序组件准备好后动态呈现这些组件。 使用 Angular 7 和 Gridster2。
【问题讨论】:
-
<div [innerHTML]="item.name"></div>....呢? -
@Edison 它在 dashlet 容器内创建了一个空的 div。它没有渲染组件。
-
Angular 有一个非常好的使用动态组件的指南。我认为你应该参考这个:angular.io/guide/dynamic-component-loader
-
所以所有字符串 (
component-selectors) 都是同一个模块的一部分? -
为什么要使用标签?!为什么不使用 CompnentClass 作为数组中的元素。这将使组件加载器工厂更容易。
标签: angular typescript dashboard gridster