【发布时间】:2020-02-17 06:25:06
【问题描述】:
我有两个数组变量,需要渲染相同的 html 内容。
notification = [...]
disruptionNotification = [...]
下面是我的 HTML,
<ng-container *ngFor="let notification of notifications; let i = index">
<ng-container *ngTemplateOutlet="notification"></ng-container>
</ng-container>
<ng-container *ngFor="let notification of disruptionNotification; let i = index">
<ng-container *ngTemplateOutlet="notification"></ng-container>
</ng-container>
<ng-template #notification>
<tag-notification [type]="notification.type">
<ng-container *ngIf="notification.titleLink && notification.title; else bwcNotificationTitleOnly">
....
</ng-container>
</tag-notification>
</ng-template>
但是渲染后,我是这个错误TypeError: templateRef.createEmbeddedView is not a function
StackBlitz 链接:https://stackblitz.com/edit/angular-bxcmrp
预期的结果应该是,
This is Title
This is Title
This is disruptionNotifications
This is disruptionNotifications
【问题讨论】:
-
你能创建一个重现问题的小提琴吗?
-
在我的情况下,错误是由于我在 ngTemplateOutlet 之前忘记了 *(星号)
标签: javascript angular typescript