[英]Angular Template reference throwing error
我有兩個數組變量,它們需要呈現相同的 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
您在 *ngIf else 子句中引用的任何元素都不能是任意組件,但它必須是 ng-template。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.